Skip to content

Commit 0d9fa77

Browse files
committed
avoid code duplication for disabling parallelization with xUnit
1 parent 12a8819 commit 0d9fa77

File tree

31 files changed

+50
-74
lines changed

31 files changed

+50
-74
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Xunit;
5+
6+
namespace System
7+
{
8+
[CollectionDefinition(nameof(DisableParallelization), DisableParallelization = true)]
9+
public class DisableParallelization { }
10+
}

src/libraries/Common/tests/TestUtilities/TestUtilities.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Compile Include="System\AdminHelpers.cs" />
1919
<Compile Include="System\AssertExtensions.cs" />
2020
<Compile Include="System\IO\StreamExtensions.cs" />
21+
<Compile Include="System\DisableParallelization.cs" />
2122
<Compile Include="System\RetryHelper.cs" />
2223
<Compile Include="System\Buffers\BoundedMemory.cs" />
2324
<Compile Include="System\Buffers\BoundedMemory.Creation.cs" />

src/libraries/System.ComponentModel.TypeConverter/tests/MemberDescriptorTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
namespace System.ComponentModel.Tests
1111
{
12-
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
13-
public partial class NoParallelTests { }
14-
1512
// Mutable static comparision in the implementation
16-
[Collection("NoParallelTests")]
13+
[Collection(nameof(DisableParallelization))]
1714
public class MemberDescriptorTests
1815
{
1916
[Theory]

src/libraries/System.ComponentModel.TypeConverter/tests/ReflectionCachesUpdateHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace System.ComponentModel.Tests
88
{
99
[SimpleUpdateTest]
10-
[Collection("NoParallelTests")] // Clears the cache which disrupts concurrent tests
10+
[Collection(nameof(DisableParallelization))] // Clears the cache which disrupts concurrent tests
1111
public class ReflectionCachesUpdateHandlerTests
1212
{
1313
[Fact]

src/libraries/System.ComponentModel.TypeConverter/tests/TypeDescriptorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace System.ComponentModel.Tests
1212
{
13-
[Collection("NoParallelTests")] // manipulates cache
13+
[Collection(nameof(DisableParallelization))] // manipulates cache
1414
public class TypeDescriptorTests
1515
{
1616
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))] // Mock will try to JIT

src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ public void FileSystemWatcher_ModifyFiltersConcurrentWithEvents()
10861086
}
10871087
}
10881088

1089-
[Collection("NoParallelTests")]
1089+
[Collection(nameof(DisableParallelization))]
10901090
public partial class DangerousFileSystemWatcherTests : FileSystemWatcherTest
10911091
{
10921092
private readonly ITestOutputHelper _output;

src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace System.IO.Tests
1313
{
14-
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
15-
public partial class NoParallelTests { }
16-
1714
public abstract partial class FileSystemWatcherTest : FileCleanupTestBase
1815
{
1916
// Events are reported asynchronously by the OS, so allow an amount of time for

src/libraries/System.IO.FileSystem/tests/FileStream/FileStreamConformanceTests.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected override string GetTestFilePath(int? index = null, [CallerMemberName]
7777
}
7878

7979
[PlatformSpecific(TestPlatforms.Windows)] // the test setup is Windows-specifc
80-
[Collection("NoParallelTests")] // don't run in parallel, as file sharing logic is not thread-safe
80+
[Collection(nameof(DisableParallelization))] // don't run in parallel, as file sharing logic is not thread-safe
8181
[OuterLoop("Requires admin privileges to create a file share")]
8282
[ConditionalClass(typeof(UncFilePathFileStreamStandaloneConformanceTests), nameof(CanShareFiles))]
8383
public class UncFilePathFileStreamStandaloneConformanceTests : UnbufferedAsyncFileStreamStandaloneConformanceTests

src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace System.IO.Tests
1010
// Don't run in parallel as the WhenDiskIsFullTheErrorMessageContainsAllDetails test
1111
// consumes entire available free space on the disk (only on Linux, this is how posix_fallocate works)
1212
// and if we try to run other disk-writing test in the meantime we are going to get "No space left on device" exception.
13-
[Collection("NoParallelTests")]
13+
[Collection(nameof(DisableParallelization))]
1414
public partial class FileStream_ctor_options : FileStream_ctor_str_fm_fa_fs_buffer_fo
1515
{
1616
protected override string GetExpectedParamName(string paramName) => "value";
@@ -166,7 +166,4 @@ public void WhenDiskIsFullTheErrorMessageContainsAllDetails(FileMode mode)
166166
Assert.False(exists);
167167
}
168168
}
169-
170-
[CollectionDefinition("NoParallelTests", DisableParallelization = true)]
171-
public partial class NoParallelTests { }
172169
}

src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2FlowControl.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111

1212
namespace System.Net.Http.Functional.Tests
1313
{
14-
[CollectionDefinition(nameof(NonParallelTestCollection), DisableParallelization = true)]
15-
public class NonParallelTestCollection
16-
{
17-
}
18-
1914
// This test class contains tests which are strongly timing-dependent.
2015
// There are two mitigations avoid flaky behavior on CI:
2116
// - Parallel test execution is disabled
2217
// - Using extreme parameters, and checks which are very unlikely to fail, if the implementation is correct
23-
[Collection(nameof(NonParallelTestCollection))]
18+
[Collection(nameof(DisableParallelization))]
2419
[ConditionalClass(typeof(SocketsHttpHandler_Http2FlowControl_Test), nameof(IsSupported))]
2520
public sealed class SocketsHttpHandler_Http2FlowControl_Test : HttpClientHandlerTestBase
2621
{

0 commit comments

Comments
 (0)