1- /// <summary>
2- /// Test collection for tests that require exclusive execution (no parallel execution with any other tests).
3- /// This is needed for tests that use OpenTelemetry TracerProvider with the global static ActivitySource.
4- /// Without this, the TracerProvider would collect activities from ALL tests running in parallel.
5- /// </summary>
6- /// <remarks>
7- /// The fixture ensures mutual exclusion across ALL tests by using a static semaphore.
8- /// Tests in this collection will acquire the semaphore before running and release it after,
9- /// preventing any other test from running concurrently.
10- /// </remarks>
11- [ CollectionDefinition ( nameof ( ExclusiveExecution ) ) ]
12- public sealed class ExclusiveExecution : ICollectionFixture < ExclusiveExecutionFixture > ;
1+ // Uncomment to disable parallel test execution for the whole assembly
2+ //[assembly: CollectionBehavior(DisableTestParallelization = true)]
133
144/// <summary>
15- /// Fixture that ensures only one test runs at a time across the entire test assembly.
5+ /// Enables test classes to individually be attributed as [Collection(nameof(DisableParallelization))]
6+ /// to have those tests run non-concurrently with any other tests.
167/// </summary>
17- public sealed class ExclusiveExecutionFixture : IAsyncLifetime
18- {
19- private static readonly SemaphoreSlim s_exclusiveLock = new ( 1 , 1 ) ;
20-
21- public async ValueTask InitializeAsync ( )
22- {
23- // Acquire the lock before any test in this collection starts
24- await s_exclusiveLock . WaitAsync ( ) ;
25- }
26-
27- public ValueTask DisposeAsync ( )
28- {
29- // Release the lock after the test completes
30- s_exclusiveLock . Release ( ) ;
31- return default ;
32- }
33- }
8+ [ CollectionDefinition ( nameof ( DisableParallelization ) , DisableParallelization = true ) ]
9+ public sealed class DisableParallelization ;
0 commit comments