From abc35d5527b1621e4e672768688f1b9461cbe14a Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 21 Jun 2016 10:53:07 +0900 Subject: [PATCH] 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 --- tests/cts/net/src/android/net/cts/DnsTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/DnsTest.java b/tests/cts/net/src/android/net/cts/DnsTest.java index c6a8962748..8575c338dd 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 @@ public class DnsTest extends AndroidTestCase { 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 @@ public class DnsTest extends AndroidTestCase { 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 @@ public class DnsTest extends AndroidTestCase { 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()); }