diff --git a/src/Paramore.Fences.Core/Utils/CancellationTokenSourcePool.Pooled.cs b/src/Paramore.Fences.Core/Utils/CancellationTokenSourcePool.Pooled.cs index b01b28ff..c622865d 100644 --- a/src/Paramore.Fences.Core/Utils/CancellationTokenSourcePool.Pooled.cs +++ b/src/Paramore.Fences.Core/Utils/CancellationTokenSourcePool.Pooled.cs @@ -3,7 +3,7 @@ namespace Paramore.Fences.Utils; internal abstract partial class CancellationTokenSourcePool { #if NET6_0_OR_GREATER - private sealed class PooledCancellationTokenSourcePool : CancellationTokenSourcePool + internal sealed class PooledCancellationTokenSourcePool : CancellationTokenSourcePool { public static readonly PooledCancellationTokenSourcePool SystemInstance = new(TimeProvider.System); diff --git a/test/Paramore.Fences.Core.Tests/Utils/CancellationTokenSourcePoolTests.cs b/test/Paramore.Fences.Core.Tests/Utils/CancellationTokenSourcePoolTests.cs index 117ea1fd..3b2d7ce8 100644 --- a/test/Paramore.Fences.Core.Tests/Utils/CancellationTokenSourcePoolTests.cs +++ b/test/Paramore.Fences.Core.Tests/Utils/CancellationTokenSourcePoolTests.cs @@ -30,7 +30,15 @@ public void ArgValidation_Ok() [Theory] public void RentReturn_Reusable_EnsureProperBehavior(object timeProvider) { + // Use a dedicated pool instance instead of CancellationTokenSourcePool.Create(...), which + // returns a process-wide shared singleton for TimeProvider.System. Using the shared singleton + // makes this test flaky, as other tests running in parallel can rent/return CancellationTokenSource + // instances from the same pool concurrently, changing which instance is returned by Get(). +#if NET6_0_OR_GREATER + var pool = new CancellationTokenSourcePool.PooledCancellationTokenSourcePool(GetTimeProvider(timeProvider)); +#else var pool = CancellationTokenSourcePool.Create(GetTimeProvider(timeProvider)); +#endif var cts = pool.Get(System.Threading.Timeout.InfiniteTimeSpan); pool.Return(cts);