From 9e3eb070c8ef2b348361ae0d7ab38567971b4a4e Mon Sep 17 00:00:00 2001 From: iancooper Date: Sun, 27 Sep 2026 11:19:20 +0100 Subject: [PATCH 1/2] refactor: make PooledCancellationTokenSourcePool internal Structural half of the App-vNext/Polly@9ad5ae9b port. The nested type was private; widening it to internal lets tests construct a dedicated pool. Its enclosing class is internal, so the public API is unchanged. Refs #28. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Utils/CancellationTokenSourcePool.Pooled.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 721b289ec8b6d7b810ef520b633af225b4716bdc Mon Sep 17 00:00:00 2001 From: iancooper Date: Sun, 27 Sep 2026 11:21:07 +0100 Subject: [PATCH 2/2] Port App-vNext/Polly@9ad5ae9b: fix flaky pool test with a dedicated pool RentReturn_Reusable_EnsureProperBehavior used CancellationTokenSourcePool.Create, which returns a process-wide singleton for TimeProvider.System on .NET 6+. Parallel tests renting from the same pool could change which instance Get() returned. The test now constructs its own PooledCancellationTokenSourcePool. Upstream: App-vNext/Polly#3231. Refs #28. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Utils/CancellationTokenSourcePoolTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) 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);