Fix flaky CancellationTokenSourcePool test with a dedicated pool - #43
Merged
Merged
Conversation
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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of App-vNext/Polly@9ad5ae9b (upstream App-vNext/Polly#3231), from upstream sync #1. Refs #28.
What
On .NET 6+,
CancellationTokenSourcePool.Create(TimeProvider.System)returns a process-wide singleton.RentReturn_Reusable_EnsureProperBehaviorrented from that shared pool, so tests running in parallel could rent or return instances concurrently and change which oneGet()returned. That made the test flaky.This PR has two commits, split structural from behavioural (tidy first):
refactor:the nestedPooledCancellationTokenSourcePoolgoes fromprivatetointernal, so the test can construct it.#if NET6_0_OR_GREATERand keepsCreate(...)in the#else. It carries upstream's comment explaining why.For the
FakeTimeProviderrow nothing changes: on .NET 8+Create()already returned a fresh pool for non-System providers. Only the System row stops sharing the singleton.Checks
internal, so there's no public API change (ADR 0003 D7) and.PublicAPI/is untouched. No dependency changes.CHANGELOG.mdis untouched. It is generated from PR titles at release time.ComponentDisposeHelper.cs:30). Unmodifiedmaindoes the same, so this isn't caused by this change. See Coverage collection is unreliable, and blocks the coverlet 10 upgrade #14.🤖 Generated with Claude Code