From 2114a13b236875628c51023963ce684caa6f1d39 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 11 May 2016 09:11:17 -0400 Subject: [PATCH] [System][tests] Tweak Dns unit tests so it does not fail on an IPv6 only network Some existing tests only works when IPv4 is available, which was fine as it match how we historically ran those tests. Apple has a new requirement [1] to test under an "IPv6 only network" and the change facilitate this. [1] https://developer.apple.com/news/?id=05042016a --- mcs/class/System/Test/System.Net/DnsTest.cs | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mcs/class/System/Test/System.Net/DnsTest.cs b/mcs/class/System/Test/System.Net/DnsTest.cs index fe3769fd545..6487e117846 100644 --- a/mcs/class/System/Test/System.Net/DnsTest.cs +++ b/mcs/class/System/Test/System.Net/DnsTest.cs @@ -55,8 +55,9 @@ namespace MonoTests.System.Net IAsyncResult async = Dns.BeginResolve (site1Dot, null, null); IPHostEntry entry = Dns.EndResolve (async); - SubTestValidIPHostEntry (entry); - Assert.AreEqual (site1Dot, entry.AddressList [0].ToString ()); + SubTestValidIPHostEntry (entry); + var ip = GetNonIPv6Address (entry); + Assert.AreEqual (site1Dot, ip.ToString ()); } void ResolveCallback (IAsyncResult ar) @@ -205,12 +206,21 @@ namespace MonoTests.System.Net } } + static IPAddress GetNonIPv6Address (IPHostEntry h) + { + var al0 = h.AddressList [0]; + if (al0.AddressFamily == AddressFamily.InterNetworkV6) + Assert.Ignore ("Resolve address is incompatible, e.g. running on an IPv6 only network"); + return al0; + } + void SubTestGetHostByName (string siteName, string siteDot) { IPHostEntry h = Dns.GetHostByName (siteName); SubTestValidIPHostEntry (h); Assert.AreEqual (siteName, h.HostName, "siteName"); - Assert.AreEqual (siteDot, h.AddressList [0].ToString (), "siteDot"); + var ip = GetNonIPv6Address (h); + Assert.AreEqual (siteDot, ip.ToString (), "siteDot"); } [Test] @@ -287,7 +297,8 @@ namespace MonoTests.System.Net IPAddress addr = new IPAddress (IPAddress.NetworkToHostOrder ((int) site1IP)); IPHostEntry h = Dns.GetHostByAddress (addr); SubTestValidIPHostEntry (h); - Assert.AreEqual (addr.ToString (), h.AddressList [0].ToString ()); + var ip = GetNonIPv6Address (h); + Assert.AreEqual (addr.ToString (), ip.ToString ()); } [Test] @@ -295,8 +306,9 @@ namespace MonoTests.System.Net { IPAddress addr = new IPAddress (IPAddress.NetworkToHostOrder ((int) site2IP)); IPHostEntry h = Dns.GetHostByAddress (addr); - SubTestValidIPHostEntry (h); - Assert.AreEqual (addr.ToString (), h.AddressList [0].ToString ()); + SubTestValidIPHostEntry (h); + var ip = GetNonIPv6Address (h); + Assert.AreEqual (addr.ToString (), ip.ToString ()); } [Test] -- 2.25.1