Skip to content

Fix flaky CancellationTokenSourcePool test with a dedicated pool - #43

Merged
iancooper merged 3 commits into
mainfrom
port/9ad5ae9b-dedicated-pool-test
Sep 27, 2026
Merged

iancooper merged 3 commits into
mainfrom
port/9ad5ae9b-dedicated-pool-test

Conversation

@iancooper

Copy link
Copy Markdown
Member

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_EnsureProperBehavior rented from that shared pool, so tests running in parallel could rent or return instances concurrently and change which one Get() returned. That made the test flaky.

This PR has two commits, split structural from behavioural (tidy first):

  1. refactor: the nested PooledCancellationTokenSourcePool goes from private to internal, so the test can construct it.
  2. The test builds its own dedicated pool under #if NET6_0_OR_GREATER and keeps Create(...) in the #else. It carries upstream's comment explaining why.

For the FakeTimeProvider row nothing changes: on .NET 8+ Create() already returned a fresh pool for non-System providers. Only the System row stops sharing the singleton.

Checks

  • No product behaviour change. The enclosing class is internal, so there's no public API change (ADR 0003 D7) and .PublicAPI/ is untouched. No dependency changes.
  • Analyser-clean build. Core tests pass on net10.0, net9.0 and net8.0.
  • CHANGELOG.md is untouched. It is generated from PR titles at release time.
  • Locally, coverlet intermittently reports 99.96% line coverage (ComponentDisposeHelper.cs:30). Unmodified main does 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

iancooper and others added 2 commits September 27, 2026 11:19
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>
@iancooper
iancooper merged commit ff509d4 into main Sep 27, 2026
23 checks passed
@iancooper
iancooper deleted the port/9ad5ae9b-dedicated-pool-test branch September 27, 2026 11:10
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant