Skip to content

Commit 6d79c7e

Browse files
authored
Make LocalEndPointTest and some Connect tests non-parallel (#56399)
1 parent e505d08 commit 6d79c7e

File tree

2 files changed

+90
-50
lines changed

2 files changed

+90
-50
lines changed

src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs

Lines changed: 85 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,56 +83,6 @@ public async Task Connect_MultipleIPAddresses_Success(IPAddress listenAt)
8383
}
8484
}
8585

86-
[Fact]
87-
public async Task Connect_DualMode_MultiAddressFamilyConnect_RetrievedEndPoints_Success()
88-
{
89-
if (!SupportsMultiConnect)
90-
return;
91-
92-
int port;
93-
using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port))
94-
using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp))
95-
{
96-
Assert.True(client.DualMode);
97-
98-
await MultiConnectAsync(client, new IPAddress[] { IPAddress.IPv6Loopback, IPAddress.Loopback }, port);
99-
100-
CheckIsIpv6LoopbackEndPoint(client.LocalEndPoint);
101-
CheckIsIpv6LoopbackEndPoint(client.RemoteEndPoint);
102-
}
103-
}
104-
105-
[Fact]
106-
[ActiveIssue("https://github.com/dotnet/runtime/issues/55709", TestPlatforms.Linux)]
107-
public async Task Connect_DualMode_DnsConnect_RetrievedEndPoints_Success()
108-
{
109-
var localhostAddresses = Dns.GetHostAddresses("localhost");
110-
if (Array.IndexOf(localhostAddresses, IPAddress.Loopback) == -1 ||
111-
Array.IndexOf(localhostAddresses, IPAddress.IPv6Loopback) == -1)
112-
{
113-
return;
114-
}
115-
116-
int port;
117-
using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port))
118-
using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp))
119-
{
120-
Assert.True(client.DualMode);
121-
122-
await ConnectAsync(client, new DnsEndPoint("localhost", port));
123-
124-
CheckIsIpv6LoopbackEndPoint(client.LocalEndPoint);
125-
CheckIsIpv6LoopbackEndPoint(client.RemoteEndPoint);
126-
}
127-
}
128-
129-
private static void CheckIsIpv6LoopbackEndPoint(EndPoint endPoint)
130-
{
131-
IPEndPoint ep = endPoint as IPEndPoint;
132-
Assert.NotNull(ep);
133-
Assert.True(ep.Address.Equals(IPAddress.IPv6Loopback) || ep.Address.Equals(IPAddress.Loopback.MapToIPv6()));
134-
}
135-
13686
[Fact]
13787
public async Task Connect_OnConnectedSocket_Fails()
13888
{
@@ -391,4 +341,89 @@ public async Task ConnectHostNameAndPort_CancelDuringConnect_Throws()
391341
}
392342
}
393343
}
344+
345+
// The test class is declared non-parallel because of possible IPv4/IPv6 port-collision on Unix:
346+
// When running these tests in parallel with other tests, there is some chance that the DualMode client
347+
// will connect to an IPv4 server of a parallel test case.
348+
[Collection(nameof(NoParallelTests))]
349+
public abstract class Connect_NonParallel<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
350+
{
351+
protected Connect_NonParallel(ITestOutputHelper output) : base(output)
352+
{
353+
}
354+
355+
[Fact]
356+
public async Task Connect_DualMode_MultiAddressFamilyConnect_RetrievedEndPoints_Success()
357+
{
358+
if (!SupportsMultiConnect)
359+
return;
360+
361+
int port;
362+
using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port))
363+
using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp))
364+
{
365+
Assert.True(client.DualMode);
366+
367+
await MultiConnectAsync(client, new IPAddress[] { IPAddress.IPv6Loopback, IPAddress.Loopback }, port);
368+
369+
CheckIsIpv6LoopbackEndPoint(client.LocalEndPoint);
370+
CheckIsIpv6LoopbackEndPoint(client.RemoteEndPoint);
371+
}
372+
}
373+
374+
[Fact]
375+
public async Task Connect_DualMode_DnsConnect_RetrievedEndPoints_Success()
376+
{
377+
var localhostAddresses = Dns.GetHostAddresses("localhost");
378+
if (Array.IndexOf(localhostAddresses, IPAddress.Loopback) == -1 ||
379+
Array.IndexOf(localhostAddresses, IPAddress.IPv6Loopback) == -1)
380+
{
381+
return;
382+
}
383+
384+
int port;
385+
using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, IPAddress.Loopback, out port))
386+
using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp))
387+
{
388+
Assert.True(client.DualMode);
389+
390+
await ConnectAsync(client, new DnsEndPoint("localhost", port));
391+
392+
CheckIsIpv6LoopbackEndPoint(client.LocalEndPoint);
393+
CheckIsIpv6LoopbackEndPoint(client.RemoteEndPoint);
394+
}
395+
}
396+
397+
private static void CheckIsIpv6LoopbackEndPoint(EndPoint endPoint)
398+
{
399+
IPEndPoint ep = endPoint as IPEndPoint;
400+
Assert.NotNull(ep);
401+
Assert.True(ep.Address.Equals(IPAddress.IPv6Loopback) || ep.Address.Equals(IPAddress.Loopback.MapToIPv6()));
402+
}
403+
}
404+
405+
public sealed class ConnectSync_NonParallel : Connect_NonParallel<SocketHelperArraySync>
406+
{
407+
public ConnectSync_NonParallel(ITestOutputHelper output) : base(output) { }
408+
}
409+
410+
public sealed class ConnectSyncForceNonBlocking_NonParallel : Connect_NonParallel<SocketHelperSyncForceNonBlocking>
411+
{
412+
public ConnectSyncForceNonBlocking_NonParallel(ITestOutputHelper output) : base(output) { }
413+
}
414+
415+
public sealed class ConnectApm_NonParallel : Connect_NonParallel<SocketHelperApm>
416+
{
417+
public ConnectApm_NonParallel(ITestOutputHelper output) : base(output) { }
418+
}
419+
420+
public sealed class ConnectTask_NonParallel : Connect_NonParallel<SocketHelperTask>
421+
{
422+
public ConnectTask_NonParallel(ITestOutputHelper output) : base(output) { }
423+
}
424+
425+
public sealed class ConnectEap_NonParallel : Connect_NonParallel<SocketHelperEap>
426+
{
427+
public ConnectEap_NonParallel(ITestOutputHelper output) : base(output) { }
428+
}
394429
}

src/libraries/System.Net.Sockets/tests/FunctionalTests/LocalEndPointTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
namespace System.Net.Sockets.Tests
99
{
10+
// The test class is declared non-parallel because of possible IPv4/IPv6 port-collision on Unix:
11+
// When running in parallel with other tests, there is some chance that Accept() calls in LocalEndPointTest will
12+
// accept a connection request from another, DualMode client living in a parallel test
13+
// that is intended to connect to a server of opposite AddressFamily in the parallel test.
14+
[Collection(nameof(NoParallelTests))]
1015
public abstract class LocalEndPointTest<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
1116
{
1217
protected abstract bool IPv6 { get; }

0 commit comments

Comments
 (0)