Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid code duplication for disabling parallelization with xUnit #62132

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace System
{
[CollectionDefinition(nameof(DisableParallelization), DisableParallelization = true)]
public class DisableParallelization { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="System\AdminHelpers.cs" />
<Compile Include="System\AssertExtensions.cs" />
<Compile Include="System\IO\StreamExtensions.cs" />
<Compile Include="System\DisableParallelization.cs" />
<Compile Include="System\RetryHelper.cs" />
<Compile Include="System\Buffers\BoundedMemory.cs" />
<Compile Include="System\Buffers\BoundedMemory.Creation.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

namespace System.ComponentModel.Tests
{
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }

// Mutable static comparision in the implementation
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public class MemberDescriptorTests
{
[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace System.ComponentModel.Tests
{
[SimpleUpdateTest]
[Collection("NoParallelTests")] // Clears the cache which disrupts concurrent tests
[Collection(nameof(DisableParallelization))] // Clears the cache which disrupts concurrent tests
public class ReflectionCachesUpdateHandlerTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace System.ComponentModel.Tests
{
[Collection("NoParallelTests")] // manipulates cache
[Collection(nameof(DisableParallelization))] // manipulates cache
public class TypeDescriptorTests
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] // Mock will try to JIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ public void FileSystemWatcher_ModifyFiltersConcurrentWithEvents()
}
}

[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public partial class DangerousFileSystemWatcherTests : FileSystemWatcherTest
{
private readonly ITestOutputHelper _output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

namespace System.IO.Tests
{
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }

public abstract partial class FileSystemWatcherTest : FileCleanupTestBase
{
// Events are reported asynchronously by the OS, so allow an amount of time for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override string GetTestFilePath(int? index = null, [CallerMemberName]
}

[PlatformSpecific(TestPlatforms.Windows)] // the test setup is Windows-specifc
[Collection("NoParallelTests")] // don't run in parallel, as file sharing logic is not thread-safe
[Collection(nameof(DisableParallelization))] // don't run in parallel, as file sharing logic is not thread-safe
[OuterLoop("Requires admin privileges to create a file share")]
[ConditionalClass(typeof(UncFilePathFileStreamStandaloneConformanceTests), nameof(CanShareFiles))]
public class UncFilePathFileStreamStandaloneConformanceTests : UnbufferedAsyncFileStreamStandaloneConformanceTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.IO.Tests
// Don't run in parallel as the WhenDiskIsFullTheErrorMessageContainsAllDetails test
// consumes entire available free space on the disk (only on Linux, this is how posix_fallocate works)
// and if we try to run other disk-writing test in the meantime we are going to get "No space left on device" exception.
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public partial class FileStream_ctor_options : FileStream_ctor_str_fm_fa_fs_buffer_fo
{
protected override string GetExpectedParamName(string paramName) => "value";
Expand Down Expand Up @@ -166,7 +166,4 @@ public void WhenDiskIsFullTheErrorMessageContainsAllDetails(FileMode mode)
Assert.False(exists);
}
}

[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@

namespace System.Net.Http.Functional.Tests
{
[CollectionDefinition(nameof(NonParallelTestCollection), DisableParallelization = true)]
public class NonParallelTestCollection
{
}

// This test class contains tests which are strongly timing-dependent.
// There are two mitigations avoid flaky behavior on CI:
// - Parallel test execution is disabled
// - Using extreme parameters, and checks which are very unlikely to fail, if the implementation is correct
[Collection(nameof(NonParallelTestCollection))]
[Collection(nameof(DisableParallelization))]
[ConditionalClass(typeof(SocketsHttpHandler_Http2FlowControl_Test), nameof(IsSupported))]
public sealed class SocketsHttpHandler_Http2FlowControl_Test : HttpClientHandlerTestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace System.Net.Http.Functional.Tests
{
[Collection(nameof(NonParallelTestCollection))]
[Collection(nameof(DisableParallelization))]
[ConditionalClass(typeof(SocketsHttpHandler_Http2KeepAlivePing_Test), nameof(IsSupported))]
public sealed class SocketsHttpHandler_Http2KeepAlivePing_Test : HttpClientHandlerTestBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3143,23 +3143,23 @@ public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http2(ITestOutputH
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_Http3_MsQuic : HttpClientHandlerTest_Http3
{
public SocketsHttpHandlerTest_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.MsQuic;
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_Http3_Mock : HttpClientHandlerTest_Http3
{
public SocketsHttpHandlerTest_Http3_Mock(ITestOutputHelper output) : base(output) { }
protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.Mock;
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_MsQuic : HttpClientHandlerTest
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3168,7 +3168,7 @@ public SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_MsQuic(ITestOutputHelp
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_Mock : HttpClientHandlerTest
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_Mock(ITestOutputHelper output) : base(output) { }
Expand All @@ -3177,7 +3177,7 @@ public SocketsHttpHandlerTest_HttpClientHandlerTest_Http3_Mock(ITestOutputHelper
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_Cookies_Http3_MsQuic : HttpClientHandlerTest_Cookies
{
public SocketsHttpHandlerTest_Cookies_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3186,7 +3186,7 @@ public SocketsHttpHandlerTest_Cookies_Http3_MsQuic(ITestOutputHelper output) : b
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_Cookies_Http3_Mock : HttpClientHandlerTest_Cookies
{
public SocketsHttpHandlerTest_Cookies_Http3_Mock(ITestOutputHelper output) : base(output) { }
Expand All @@ -3195,7 +3195,7 @@ public SocketsHttpHandlerTest_Cookies_Http3_Mock(ITestOutputHelper output) : bas
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_MsQuic : HttpClientHandlerTest_Headers
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3204,7 +3204,7 @@ public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_MsQuic(ITestOu
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_Mock : HttpClientHandlerTest_Headers
{
public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_Mock(ITestOutputHelper output) : base(output) { }
Expand All @@ -3213,7 +3213,7 @@ public SocketsHttpHandlerTest_HttpClientHandlerTest_Headers_Http3_Mock(ITestOutp
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_MsQuic : SocketsHttpHandler_Cancellation_Test
{
public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3222,7 +3222,7 @@ public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_MsQuic(ITest
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_Mock : SocketsHttpHandler_Cancellation_Test
{
public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_Mock(ITestOutputHelper output) : base(output) { }
Expand All @@ -3231,7 +3231,7 @@ public SocketsHttpHandler_HttpClientHandler_Cancellation_Test_Http3_Mock(ITestOu
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_MsQuic : HttpClientHandler_AltSvc_Test
{
public SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3240,7 +3240,7 @@ public SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_MsQuic(ITestOutput
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_Mock : HttpClientHandler_AltSvc_Test
{
public SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_Mock(ITestOutputHelper output) : base(output) { }
Expand All @@ -3249,7 +3249,7 @@ public SocketsHttpHandler_HttpClientHandler_AltSvc_Test_Http3_Mock(ITestOutputHe
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMsQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http3_MsQuic : HttpClientHandler_Finalization_Test
{
public SocketsHttpHandler_HttpClientHandler_Finalization_Http3_MsQuic(ITestOutputHelper output) : base(output) { }
Expand All @@ -3258,18 +3258,14 @@ public SocketsHttpHandler_HttpClientHandler_Finalization_Http3_MsQuic(ITestOutpu
}

[ConditionalClass(typeof(HttpClientHandlerTestBase), nameof(IsMockQuicSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class SocketsHttpHandler_HttpClientHandler_Finalization_Http3_Mock : HttpClientHandler_Finalization_Test
{
public SocketsHttpHandler_HttpClientHandler_Finalization_Http3_Mock(ITestOutputHelper output) : base(output) { }
protected override Version UseVersion => HttpVersion.Version30;
protected override QuicImplementationProvider UseQuicImplementationProvider => QuicImplementationProviders.Mock;
}

// Define test collection for tests to avoid all other tests.
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }

[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
public abstract class SocketsHttpHandler_RequestValidationTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace System.Net.NameResolution.Tests
{
using Configuration = System.Net.Test.Common.Configuration;

[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public class LoggingTest
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

namespace System.Net.NameResolution.Tests
{
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }

internal static class TestSettings
{
// A hostname that will not exist in any DNS caches, forcing some I/O to lookup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace System.Net.Quic.Tests
{
[ConditionalClass(typeof(QuicTestBase<MsQuicProviderFactory>), nameof(IsSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public class MsQuicTests : QuicTestBase<MsQuicProviderFactory>
{
private static byte[] s_data = Encoding.UTF8.GetBytes("Hello world!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class MockQuicStreamConformanceTests : QuicStreamConformanceTests
}

[ConditionalClass(typeof(QuicTestBase<MsQuicProviderFactory>), nameof(QuicTestBase<MsQuicProviderFactory>.IsSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class MsQuicQuicStreamConformanceTests : QuicStreamConformanceTests
{
protected override QuicImplementationProvider Provider => QuicImplementationProviders.MsQuic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,9 @@ public QuicStreamTests_MockProvider(ITestOutputHelper output) : base(output) { }
}

[ConditionalClass(typeof(QuicTestBase<MsQuicProviderFactory>), nameof(QuicTestBase<MsQuicProviderFactory>.IsSupported))]
[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
public sealed class QuicStreamTests_MsQuicProvider : QuicStreamTests<MsQuicProviderFactory>
{
public QuicStreamTests_MsQuicProvider(ITestOutputHelper output) : base(output) { }
}

// Define test collection for tests to avoid all other tests.
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
public partial class NoParallelTests { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public async Task FailedConnect_ConnectedReturnsFalse()
// The test class is declared non-parallel because of possible IPv4/IPv6 port-collision on Unix:
// When running these tests in parallel with other tests, there is some chance that the DualMode client
// will connect to an IPv4 server of a parallel test case.
[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public abstract class Connect_NonParallel<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
{
protected Connect_NonParallel(ITestOutputHelper output) : base(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ private static void CreateSocketWithDanglingReference()
}
}

[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public class DisposedSocketTestsNonParallel
{
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsPreciseGcSupported))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.Net.Sockets.Tests
// When running in parallel with other tests, there is some chance that Accept() calls in LocalEndPointTest will
// accept a connection request from another, DualMode client living in a parallel test
// that is intended to connect to a server of opposite AddressFamily in the parallel test.
[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public abstract class LocalEndPointTest<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
{
protected abstract bool IPv6 { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private static void DisposeSockets(IEnumerable<KeyValuePair<Socket, Socket>> soc
}
}

[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public class SelectTest_NonParallel
{
[OuterLoop]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void EndSendFile_NullAsyncResult_Throws()

// Running all cases of GreaterThan2GBFile_SendsAllBytes in parallel may attempt to allocate Min(ProcessorCount, Subclass_Count) * 2GB of disk space
// in extreme cases. Some CI machines may run out of disk space if this happens.
[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public abstract class SendFile_NonParallel<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
{
protected SendFile_NonParallel(ITestOutputHelper output) : base(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace System.Net.Sockets.Tests
{
[Collection(nameof(NoParallelTests))]
[Collection(nameof(DisableParallelization))]
public abstract class SendReceiveNonParallel<T> : SocketTestHelperBase<T> where T : SocketHelperBase, new()
{
public SendReceiveNonParallel(ITestOutputHelper output) : base(output) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,9 @@ public void SetUnsupportedRawSocketOption_DoesNotDisconnectSocket()
private static int SOL_SOCKET = OperatingSystem.IsLinux() ? 1 : (int)SocketOptionLevel.Socket;
}

[Collection("NoParallelTests")]
[Collection(nameof(DisableParallelization))]
// Set of tests to not run together with any other tests.
public partial class NoParallelTests
public class NoParallelTests
{
[Fact]
public void BindDuringTcpWait_Succeeds()
Expand All @@ -714,7 +714,7 @@ public void BindDuringTcpWait_Succeeds()
}

// Bind a socket to the same address we just used.
// To avoid conflict with other tests, this is part of the NoParallelTests test collection.
// To avoid conflict with other tests, this is part of the DisableParallelization test collection.
using (Socket b = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
b.Bind(new IPEndPoint(IPAddress.Loopback, port));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

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
Expand Down
Loading