Skip to content

Commit 8f87ac7

Browse files
authored
avoid code duplication for disabling parallelization with xUnit (#62132)
The collection definitions must be in the same assembly as the test that uses them
1 parent fe68bf8 commit 8f87ac7

File tree

41 files changed

+68
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+68
-74
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
// The collection definitions must be in the same assembly as the test that uses them.
9+
// So please use "Compile Include" in the project file to include this class.
10+
[CollectionDefinition(nameof(DisableParallelization), DisableParallelization = true)]
11+
public class DisableParallelization { }
12+
}

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/System.ComponentModel.TypeConverter.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
<Compile Include="Security\Authentication\ExtendedProtection\ExtendedProtectionPolicyTypeConverterTests.cs" />
154154
<Compile Include="XTypeDescriptionProviderTests.cs" />
155155

156+
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs"
157+
Link="Common\TestUtilities\System\DisableParallelization.cs" />
156158
<TrimmerRootDescriptor Include="$(ILLinkDescriptorsPath)ILLink.Descriptors.Castle.xml" />
157159
</ItemGroup>
158160
<ItemGroup>

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/System.IO.FileSystem.Watcher.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
Link="Common\System\IO\TempFile.cs" />
3636
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs"
3737
Link="Common\System\IO\TempDirectory.cs" />
38+
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs"
39+
Link="Common\TestUtilities\System\DisableParallelization.cs" />
3840
</ItemGroup>
3941
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
4042
<Compile Include="FileSystemWatcher.Unix.cs" />

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/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Compile Include="..\PortedCommon\IOInputs.cs" />
2121
<Compile Include="..\PortedCommon\IOServices.cs" />
2222
<Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs" Link="Common\System\IO\PathFeatures.cs" />
23+
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
2324
</ItemGroup>
2425
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
2526
<Compile Remove="..\**\*.Windows.cs" />

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

0 commit comments

Comments
 (0)