Clear local test results across DNS lookups.
If InetAddress.getAllByName("ipv6.google.com") throws
UnknownHostException, the test silently ignores it. This
causes a misleading failure, because the test then reuses the
addrs variable that is left over from the previous DNS query
for "www.google.com", and fails because it has an IPv4 address.
Fixes: 12210306
Bug: 29231261
Change-Id: I1dde945765d40a84eba139055306b07ebc97d0ec
diff --git a/tests/cts/net/src/android/net/cts/DnsTest.java b/tests/cts/net/src/android/net/cts/DnsTest.java
index c6a8962..8575c33 100644
--- a/tests/cts/net/src/android/net/cts/DnsTest.java
+++ b/tests/cts/net/src/android/net/cts/DnsTest.java
@@ -62,8 +62,8 @@
try {
addrs = InetAddress.getAllByName("www.google.com");
} catch (UnknownHostException e) {}
- assertTrue("[RERUN] DNS could not resolve www.gooogle.com. Check internet connection",
- addrs.length != 0);
+ assertTrue("[RERUN] DNS could not resolve www.google.com. Check internet connection",
+ addrs.length != 0);
boolean foundV4 = false, foundV6 = false;
for (InetAddress addr : addrs) {
if (addr instanceof Inet4Address) foundV4 = true;
@@ -71,11 +71,8 @@
if (DBG) Log.e(TAG, "www.google.com gave " + addr.toString());
}
- // assertTrue(foundV4);
- // assertTrue(foundV6);
-
// We should have at least one of the addresses to connect!
- assertTrue(foundV4 || foundV6);
+ assertTrue("www.google.com must have IPv4 and/or IPv6 address", foundV4 || foundV6);
// Skip the rest of the test if the active network for watch is PROXY.
// TODO: Check NetworkInfo type in addition to type name once ag/601257 is merged.
@@ -85,14 +82,17 @@
return;
}
+ // Clear test state so we don't get confused with the previous results.
+ addrs = new InetAddress[0];
+ foundV4 = foundV6 = false;
try {
addrs = InetAddress.getAllByName("ipv6.google.com");
} catch (UnknownHostException e) {}
- assertTrue(addrs.length != 0);
- foundV6 = false;
+ assertTrue("[RERUN] DNS could not resolve ipv6.google.com, check the network supports IPv6",
+ addrs.length != 0);
for (InetAddress addr : addrs) {
assertFalse ("[RERUN] ipv6.google.com returned IPv4 address: " + addr.getHostAddress() +
- ", check your network's DNS connection", addr instanceof Inet4Address);
+ ", check your network's DNS server", addr instanceof Inet4Address);
foundV6 |= (addr instanceof Inet6Address);
if (DBG) Log.e(TAG, "ipv6.google.com gave " + addr.toString());
}