make sure BindDuringTcpWait_Succeeds does not run with other tests (dotnet/corefx...
authorTomas Weinfurt <tweinfurt@yahoo.com>
Thu, 12 Sep 2019 18:48:41 +0000 (11:48 -0700)
committerGitHub <noreply@github.com>
Thu, 12 Sep 2019 18:48:41 +0000 (11:48 -0700)
* 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

src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTestHelper.cs

index 84f4474..c08f393 100644 (file)
@@ -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));
+            }
+        }
+    }
 }
index ea46b5e..c090aa8 100644 (file)
@@ -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