From: Alexander Köplinger Date: Thu, 9 Jun 2016 23:37:45 +0000 (+0200) Subject: [System] Fix HttpListenerRequestTest.HttpRequestIsLocal intermittently failing X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=0178821e504551f54d2bb0b587ad07341af75427;p=mono.git [System] Fix HttpListenerRequestTest.HttpRequestIsLocal intermittently failing We're seeing the following exception on devices in CI: ``` [FAIL] HttpListenerRequestTest.HttpRequestIsLocal : System.Net.Sockets.SocketException : Could not resolve host 'XQA-AppleTV-1' at System.Net.Dns.Error_11001 (System.String hostName) [0x00000] in /Users/builder/data/lanes/1381/d8287824/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/Dns.cs:292 at System.Net.Dns.GetHostByName (System.String hostName) [0x00024] in /Users/builder/data/lanes/1381/d8287824/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/Dns.cs:419 at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00061] in /Users/builder/data/lanes/1381/d8287824/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/Dns.cs:380 at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00065] in /Users/builder/data/lanes/1381/d8287824/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net/Dns.cs:406 at MonoTests.System.Net.HttpListenerRequestTest.HttpRequestIsLocal () [0x00006] in /Users/xamarinqa/QABot/data/lanes/2441/d8287824/source/xamarin-macios/external/mono/mcs/class/System/Test/System.Net/HttpListenerRequestTest.cs:197 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Users/builder/data/lanes/1381/d8287824/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:309 ``` From looking at the code, resolving the hostname to IP addresses via DNS fails so the test doesn't even run. We don't care where the local IPs come from so we can use an alternative way of getting them - via querying the network interfaces. Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=41671 PS: fixed a hardcoded port while I was touching the code --- diff --git a/mcs/class/System/Test/System.Net/HttpListenerRequestTest.cs b/mcs/class/System/Test/System.Net/HttpListenerRequestTest.cs index c088e4e14e2..6ff1b33260e 100644 --- a/mcs/class/System/Test/System.Net/HttpListenerRequestTest.cs +++ b/mcs/class/System/Test/System.Net/HttpListenerRequestTest.cs @@ -30,6 +30,7 @@ using System; using System.IO; using System.Net; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; using System.Collections.Generic; @@ -194,15 +195,22 @@ namespace MonoTests.System.Net [Test] public void HttpRequestIsLocal () { - var ips = new List (Dns.GetHostAddresses (Dns.GetHostName ())); + var port = NetworkHelpers.FindFreePort (); + var ips = new List (); ips.Add (IPAddress.Loopback); + foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces ()) { + foreach (var ip in adapter.GetIPProperties ().UnicastAddresses) { + ips.Add (ip.Address); + } + } + foreach (var ip in ips) { if (ip.AddressFamily != AddressFamily.InterNetwork) continue; HttpListener listener = HttpListener2Test.CreateAndStartListener ( - "http://" + ip + ":9000/HttpRequestIsLocal/"); - NetworkStream ns = HttpListener2Test.CreateNS (ip, 9000); + "http://" + ip + ":" + port + "/HttpRequestIsLocal/"); + NetworkStream ns = HttpListener2Test.CreateNS (ip, port); HttpListener2Test.Send (ns, "GET /HttpRequestIsLocal/ HTTP/1.0\r\n\r\n"); HttpListenerContext ctx = listener.GetContext (); HttpListenerRequest request = ctx.Request;