diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2017-08-31 11:53:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-31 11:53:35 +0300 |
commit | e7a2d94f75e00c1f00ebe8bf02b67df7110a0b9a (patch) | |
tree | 98d857fc47b22fd971c867eca01cb7bcfded4edc /mcs/class/System | |
parent | 2439f17bef29b0bf5ae4fc81a1e7f96514810ff5 (diff) |
[bcl] Fix a few hardcoded socket ports in tests (#5471)
* [System] Fix a few hardcoded socket ports in tests
Those could've shown up as "address already in use" in CI.
* [System.Runtime.Remoting] Fix a few hardcoded socket ports in tests
Those could've shown up as "address already in use" in CI.
Additionally remove a copy of RemotingServicesTest.cs from corlib
which also exists in System.Runtime.Remoting in updated form.
* [System.ServiceModel] Fix a few hardcoded socket ports in tests
Those could've shown up as "address already in use" in CI.
* [System.Net.Http] Fix a few hardcoded socket ports in tests
Those could've shown up as "address already in use" in CI.
The additional "keep-alive" header in Send_Complete_NoContent() and
Send_Transfer_Encoding_Chunked() is because we were using the same
port for all tests before so other tests would clear the header.
This doesn't happen now that we use distinct test ports.
* [System.ServiceModel.Web] Fix a few hardcoded socket ports in tests
Those could've shown up as "address already in use" in CI.
Diffstat (limited to 'mcs/class/System')
4 files changed, 70 insertions, 71 deletions
diff --git a/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs b/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs index 4bdfd61de26..5925388413a 100755 --- a/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs @@ -30,9 +30,7 @@ namespace MonoTests.System.Net.Sockets [TestFixture] public class SocketTest { - // note: also used in SocketCas tests public const string BogusAddress = "192.168.244.244"; - public const int BogusPort = 23483; [Test] #if FEATURE_NO_BSD_SOCKETS @@ -94,7 +92,7 @@ namespace MonoTests.System.Net.Sockets public void BogusEndConnect () { IPAddress ipOne = IPAddress.Parse (BogusAddress); - IPEndPoint ipEP = new IPEndPoint (ipOne, BogusPort); + IPEndPoint ipEP = new IPEndPoint (ipOne, NetworkHelpers.FindFreePort ()); Socket sock = new Socket (ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); IAsyncResult ar = sock.BeginConnect (ipEP, null, null); @@ -501,8 +499,7 @@ namespace MonoTests.System.Net.Sockets Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, - BogusPort); + IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint (); SocketError_event.Reset (); @@ -745,8 +742,7 @@ namespace MonoTests.System.Net.Sockets Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, - BogusPort); + IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint (); Assert.AreEqual (false, sock.IsBound, "IsBoundTcp #1"); @@ -780,8 +776,7 @@ namespace MonoTests.System.Net.Sockets Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, - BogusPort); + IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint (); Assert.AreEqual (false, sock.IsBound, "IsBoundUdp #1"); @@ -1739,13 +1734,14 @@ namespace MonoTests.System.Net.Sockets [Test] public void BeginConnectAddressPortNull () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = null; try { - sock.BeginConnect (ip, 1244, BCCallback, + sock.BeginConnect (ip, port, BCCallback, sock); Assert.Fail ("BeginConnectAddressPortNull #1"); } catch (ArgumentNullException) { @@ -1782,6 +1778,7 @@ namespace MonoTests.System.Net.Sockets [ExpectedException (typeof(ObjectDisposedException))] public void BeginConnectAddressPortClosed () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -1789,7 +1786,7 @@ namespace MonoTests.System.Net.Sockets sock.Close (); - sock.BeginConnect (ip, 1244, BCCallback, sock); + sock.BeginConnect (ip, port, BCCallback, sock); } [Test] @@ -1911,13 +1908,14 @@ namespace MonoTests.System.Net.Sockets [Test] public void BeginConnectMultipleNull () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress[] ips = null; try { - sock.BeginConnect (ips, 1246, BCCallback, + sock.BeginConnect (ips, port, BCCallback, sock); Assert.Fail ("BeginConnectMultipleNull #1"); } catch (ArgumentNullException) { @@ -1961,6 +1959,7 @@ namespace MonoTests.System.Net.Sockets [ExpectedException (typeof(ObjectDisposedException))] public void BeginConnectMultipleClosed () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -1973,7 +1972,7 @@ namespace MonoTests.System.Net.Sockets sock.Close (); - sock.BeginConnect (ips, 1247, BCCallback, sock); + sock.BeginConnect (ips, port, BCCallback, sock); } [Test] @@ -2248,13 +2247,14 @@ namespace MonoTests.System.Net.Sockets [Test] public void ConnectAddressPortNull () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = null; try { - sock.Connect (ip, 1249); + sock.Connect (ip, port); Assert.Fail ("ConnectAddressPortNull #1"); } catch (ArgumentNullException) { } finally { @@ -2290,6 +2290,7 @@ namespace MonoTests.System.Net.Sockets [ExpectedException (typeof(ObjectDisposedException))] public void ConnectAddressPortClosed () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -2297,7 +2298,7 @@ namespace MonoTests.System.Net.Sockets sock.Close (); - sock.Connect (ip, 1250); + sock.Connect (ip, port); } [Test] @@ -2397,13 +2398,14 @@ namespace MonoTests.System.Net.Sockets [Test] public void ConnectMultipleNull () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress[] ips = null; try { - sock.Connect (ips, 1251); + sock.Connect (ips, port); Assert.Fail ("ConnectMultipleNull #1"); } catch (ArgumentNullException) { } finally { @@ -2445,6 +2447,7 @@ namespace MonoTests.System.Net.Sockets [ExpectedException (typeof(ObjectDisposedException))] public void ConnectMultipleClosed () { + var port = NetworkHelpers.FindFreePort (); Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); @@ -2457,7 +2460,7 @@ namespace MonoTests.System.Net.Sockets sock.Close (); - sock.Connect (ips, 1252); + sock.Connect (ips, port); } [Test] @@ -4301,7 +4304,7 @@ namespace MonoTests.System.Net.Sockets IPv6MulticastOption option = new IPv6MulticastOption ( IPAddress.Parse ("ff02::1")); - s.Bind (new IPEndPoint (IPAddress.IPv6Any, 1902)); + s.Bind (new IPEndPoint (IPAddress.IPv6Any, 0)); s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.AddMembership, option); s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DropMembership, diff --git a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs index cefe3bebc59..d827ae4de36 100644 --- a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs @@ -155,7 +155,7 @@ namespace MonoTests.System.Net.Sockets TcpClient client = new TcpClient (); IPAddress[] ipAddresses = null; - client.Connect (ipAddresses, 1234); + client.Connect (ipAddresses, NetworkHelpers.FindFreePort ()); } [Test] @@ -170,7 +170,7 @@ namespace MonoTests.System.Net.Sockets ipAddresses[0] = IPAddress.Any; try { - client.Connect (ipAddresses, 1234); + client.Connect (ipAddresses, NetworkHelpers.FindFreePort ()); Assert.Fail ("ConnectMultiAny #1"); } catch (SocketException ex) { Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2"); @@ -191,7 +191,7 @@ namespace MonoTests.System.Net.Sockets ipAddresses[0] = IPAddress.Loopback; try { - client.Connect (ipAddresses, 1234); + client.Connect (ipAddresses, NetworkHelpers.FindFreePort ()); Assert.Fail ("ConnectMultiRefused #1"); } catch (SocketException ex) { Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiRefused #2"); diff --git a/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs index 29ab8ef2ca6..1d2373b6215 100644 --- a/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs @@ -13,6 +13,8 @@ using System.Threading.Tasks; using NUnit.Framework; +using MonoTests.Helpers; + namespace MonoTests.System.Net.Sockets { [TestFixture] public class UdpClientTest { @@ -212,7 +214,7 @@ namespace MonoTests.System.Net.Sockets { IPEndPoint localEP; IPEndPoint clientEP; - clientEP = new IPEndPoint (IPAddress.Loopback, 8001); + clientEP = new IPEndPoint (IPAddress.Loopback, NetworkHelpers.FindFreePort ()); using (MyUdpClient client = new MyUdpClient (clientEP)) { s = client.Client; @@ -381,9 +383,7 @@ namespace MonoTests.System.Net.Sockets { Socket s; IPEndPoint localEP; - // Bug #5503 - // UDP port 0 doesn't seem to be valid. - using (MyUdpClient client = new MyUdpClient ("127.0.0.1", 53)) + using (MyUdpClient client = new MyUdpClient ("127.0.0.1", NetworkHelpers.FindFreePort ())) { s = client.Client; Assert.IsNotNull (s, "#A:Client"); @@ -481,7 +481,7 @@ namespace MonoTests.System.Net.Sockets { byte[] bytes = new byte[] {10, 11, 12, 13}; try { - client.Send (bytes, bytes.Length, new IPEndPoint (IPAddress.Broadcast, 1235)); + client.Send (bytes, bytes.Length, new IPEndPoint (IPAddress.Broadcast, NetworkHelpers.FindFreePort ())); } finally { client.Close (); } @@ -495,7 +495,7 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) { client.JoinMulticastGroup (mcast_addr); } } @@ -511,7 +511,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = IPAddress.Parse ("ff02::1"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) { client.JoinMulticastGroup (mcast_addr); } } @@ -522,7 +522,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void JoinMulticastGroup1_MulticastAddr_Null () { - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) { try { client.JoinMulticastGroup ((IPAddress) null); Assert.Fail ("#1"); @@ -543,7 +543,7 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = null; - UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234)); + UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0)); client.Close (); try { client.JoinMulticastGroup (mcast_addr); @@ -578,7 +578,7 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) { try { client.JoinMulticastGroup (0, mcast_addr); Assert.Fail ("#1"); @@ -606,7 +606,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = IPAddress.Parse ("ff02::1"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) { client.JoinMulticastGroup (0, mcast_addr); } } @@ -617,7 +617,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void JoinMulticastGroup2_MulticastAddr_Null () { - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) { try { client.JoinMulticastGroup (0, (IPAddress) null); Assert.Fail ("#1"); @@ -641,7 +641,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = null; - UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234)); + UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0)); client.Close (); try { client.JoinMulticastGroup (0, mcast_addr); @@ -676,11 +676,11 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) { client.JoinMulticastGroup (mcast_addr, 0); } - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) { client.JoinMulticastGroup (mcast_addr, 255); } } @@ -696,11 +696,11 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = IPAddress.Parse ("ff02::1"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) { client.JoinMulticastGroup (mcast_addr, 0); } - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) { client.JoinMulticastGroup (mcast_addr, 255); } } @@ -711,7 +711,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void JoinMulticastGroup3_MulticastAddr_Null () { - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) { try { client.JoinMulticastGroup ((IPAddress) null, int.MaxValue); Assert.Fail ("#1"); @@ -732,7 +732,7 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = null; - UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234)); + UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0)); client.Close (); try { client.JoinMulticastGroup (mcast_addr, 0); @@ -768,7 +768,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23"); IPAddress local_addr = IPAddress.Any; - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) { client.JoinMulticastGroup (mcast_addr, local_addr); } } @@ -785,7 +785,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = IPAddress.Parse ("ff02::1"); IPAddress local_addr = IPAddress.IPv6Any; - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) { try { client.JoinMulticastGroup (mcast_addr, local_addr); Assert.Fail ("#1"); @@ -810,7 +810,7 @@ namespace MonoTests.System.Net.Sockets { { IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23"); - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) { try { client.JoinMulticastGroup (mcast_addr, (IPAddress) null); Assert.Fail ("#1"); @@ -829,7 +829,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void JoinMulticastGroup4_MulticastAddr_Null () { - using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) { + using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) { try { client.JoinMulticastGroup ((IPAddress) null, IPAddress.Loopback); Assert.Fail ("#1"); @@ -851,7 +851,7 @@ namespace MonoTests.System.Net.Sockets { IPAddress mcast_addr = null; IPAddress local_addr = null; - UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234)); + UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0)); client.Close (); try { client.JoinMulticastGroup (mcast_addr, local_addr); @@ -885,18 +885,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void CloseInReceive () { - UdpClient client = null; - var rnd = new Random (); - for (int i = 0, max = 5; i < max; i++) { - int port = rnd.Next (1025, 65534); - try { - client = new UdpClient (port); - break; - } catch (Exception) { - if (i == max - 1) - throw; - } - } + UdpClient client = new UdpClient (NetworkHelpers.FindFreePort ()); ManualResetEvent ready = new ManualResetEvent (false); bool got_exc = false; @@ -928,7 +917,7 @@ namespace MonoTests.System.Net.Sockets { #endif public void JoinMulticastGroupWithLocal () { - UdpClient client = new UdpClient (9001); + UdpClient client = new UdpClient (0); IPAddress mcast_addr = IPAddress.Parse ("224.0.0.24"); IPAddress local_addr = IPAddress.Any; @@ -995,7 +984,7 @@ namespace MonoTests.System.Net.Sockets { IPEndPoint ep = null; foreach (IPAddress a in addresses) { if (a.AddressFamily == AddressFamily.InterNetwork) { - ep = new IPEndPoint (a, 1236); + ep = new IPEndPoint (a, NetworkHelpers.FindFreePort ()); break; } } @@ -1035,13 +1024,14 @@ namespace MonoTests.System.Net.Sockets { #endif public void BeginReceive () { - UdpClient client = new UdpClient (1237); + var port = NetworkHelpers.FindFreePort (); + UdpClient client = new UdpClient (port); BRCalledBack.Reset (); client.BeginReceive (BRCallback, client); - IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1237); + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, port); byte[] send_bytes = new byte[] {10, 11, 12, 13}; client.Send (send_bytes, send_bytes.Length, ep); @@ -1063,8 +1053,9 @@ namespace MonoTests.System.Net.Sockets { #endif public void Available () { - using (UdpClient client = new UdpClient (1238)) { - IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1238); + var port = NetworkHelpers.FindFreePort (); + using (UdpClient client = new UdpClient (port)) { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, port); byte[] bytes = new byte[] {10, 11, 12, 13}; int res = client.Send (bytes, bytes.Length, ep); @@ -1129,7 +1120,7 @@ namespace MonoTests.System.Net.Sockets { [Category ("NotWorking")] // Not supported on Linux public void ExclusiveAddressUseBound () { - UdpClient client = new UdpClient (1239); + UdpClient client = new UdpClient (0); client.ExclusiveAddressUse = true; @@ -1158,12 +1149,13 @@ namespace MonoTests.System.Net.Sockets { if (!Socket.OSSupportsIPv6) Assert.Ignore ("IPv6 not enabled."); - int PORT = 9997; - using(var udpClient = new UdpClient (PORT, AddressFamily.InterNetworkV6)) - using(var udpClient2 = new UdpClient (PORT+1, AddressFamily.InterNetworkV6)) + int port1 = NetworkHelpers.FindFreePort (); + int port2 = NetworkHelpers.FindFreePort (); + using(var udpClient = new UdpClient (port1, AddressFamily.InterNetworkV6)) + using(var udpClient2 = new UdpClient (port2, AddressFamily.InterNetworkV6)) { var dataSent = new byte [] {1,2,3}; - udpClient2.SendAsync (dataSent, dataSent.Length, "::1", PORT); + udpClient2.SendAsync (dataSent, dataSent.Length, "::1", port1); IPEndPoint endPoint = new IPEndPoint (IPAddress.IPv6Any, 0); var data = udpClient.Receive (ref endPoint); diff --git a/mcs/class/System/Test/System.Net/HttpListenerPrefixCollectionTest.cs b/mcs/class/System/Test/System.Net/HttpListenerPrefixCollectionTest.cs index b09a8180eaf..20763df5802 100644 --- a/mcs/class/System/Test/System.Net/HttpListenerPrefixCollectionTest.cs +++ b/mcs/class/System/Test/System.Net/HttpListenerPrefixCollectionTest.cs @@ -31,6 +31,8 @@ using System.Net; using NUnit.Framework; using HLPC=System.Net.HttpListenerPrefixCollection; +using MonoTests.Helpers; + namespace MonoTests.System.Net { [TestFixture] public class HttpListenerPrefixCollectionTest { @@ -68,10 +70,11 @@ namespace MonoTests.System.Net { #endif public void AddOne () { + var port = NetworkHelpers.FindFreePort (); HttpListener listener = new HttpListener (); HLPC coll = listener.Prefixes; listener.Start (); - coll.Add ("http://127.0.0.1:8181/"); + coll.Add ($"http://127.0.0.1:{port}/"); Assert.AreEqual (1, coll.Count, "Count"); Assert.IsFalse (coll.IsReadOnly, "IsReadOnly"); Assert.IsFalse (coll.IsSynchronized, "IsSynchronized"); @@ -84,10 +87,11 @@ namespace MonoTests.System.Net { #endif public void Duplicate () { + var port = NetworkHelpers.FindFreePort (); HttpListener listener = new HttpListener (); HLPC coll = listener.Prefixes; - coll.Add ("http://127.0.0.1:8181/"); - coll.Add ("http://127.0.0.1:8181/"); + coll.Add ($"http://127.0.0.1:{port}/"); + coll.Add ($"http://127.0.0.1:{port}/"); listener.Start (); Assert.AreEqual (1, coll.Count, "Count"); Assert.IsFalse (coll.IsReadOnly, "IsReadOnly"); |