From 55f5e6c6c7fd59124f5bee75e7778713afca59dc Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Thu, 12 Sep 2019 11:48:41 -0700 Subject: [PATCH] make sure BindDuringTcpWait_Succeeds does not run with other tests (dotnet/corefx#40958) * make sure BindDuringTcpWait_Succeeds does not run with other tests * add partial to NoParallelTests class * add empty class to CollectionDefinition Commit migrated from https://github.com/dotnet/corefx/commit/b384d34bcd4674bc0df08a333a4973de8e2ac7ae --- .../tests/FunctionalTests/SocketOptionNameTest.cs | 58 ++++++++++++---------- .../tests/FunctionalTests/SocketTestHelper.cs | 5 ++ 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs index 84f4474..c08f393 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs @@ -420,32 +420,6 @@ namespace System.Net.Sockets.Tests } } - [Fact] - public void BindDuringTcpWait_Succeeds() - { - int port = 0; - using (Socket a = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - a.Bind(new IPEndPoint(IPAddress.Loopback, 0)); - port = (a.LocalEndPoint as IPEndPoint).Port; - a.Listen(10); - - // Connect a client - using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(new IPEndPoint(IPAddress.Loopback, port)); - // accept socket and close it with zero linger time. - a.Accept().Close(0); - } - } - - // Bind a socket to the same address we just used. - using (Socket b = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) - { - b.Bind(new IPEndPoint(IPAddress.Loopback, port)); - } - } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue(11057)] public void ExclusiveAddressUseTcp() { @@ -548,4 +522,36 @@ namespace System.Net.Sockets.Tests } } } + + [Collection("NoParallelTests")] + // Set of tests to not run together with any other tests. + public partial class NoParallelTests + { + [Fact] + public void BindDuringTcpWait_Succeeds() + { + int port = 0; + using (Socket a = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + a.Bind(new IPEndPoint(IPAddress.Loopback, 0)); + port = (a.LocalEndPoint as IPEndPoint).Port; + a.Listen(10); + + // Connect a client + using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(new IPEndPoint(IPAddress.Loopback, port)); + // accept socket and close it with zero linger time. + a.Accept().Close(0); + } + } + + // Bind a socket to the same address we just used. + // To avoid conflict with other tests, this is part of the NoParallelTests test collection. + using (Socket b = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + b.Bind(new IPEndPoint(IPAddress.Loopback, port)); + } + } + } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs index ea46b5e..c090aa8 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs @@ -11,6 +11,11 @@ using Xunit.Abstractions; namespace System.Net.Sockets.Tests { + + // Define test collection for tests to avoid all other tests. + [CollectionDefinition("NoParallelTests", DisableParallelization = true)] + public partial class NoParallelTests { } + // Abstract base class for various different socket "modes" (sync, async, etc) // See SendReceive.cs for usage public abstract class SocketHelperBase -- 2.7.4