Skip to content

Fix flaky ResolverGather_TimeoutFromPrimaryRepositoryThrows test#7242

Open
dtivel wants to merge 1 commit intodevfrom
dtivel/fix-resolver-gather-race
Open

Fix flaky ResolverGather_TimeoutFromPrimaryRepositoryThrows test#7242
dtivel wants to merge 1 commit intodevfrom
dtivel/fix-resolver-gather-race

Conversation

@dtivel
Copy link
Copy Markdown
Contributor

@dtivel dtivel commented Mar 29, 2026

Bug

Fixes: NuGet/Home#14833

Description

The test ResolverGather_TimeoutFromPrimaryRepositoryThrows asserts that a primary source timeout throws InvalidOperationException. GatherPackageAsync(...) converts OperationCanceledException to InvalidOperationException, but cancellation checks in the main loop and worker task entry can fire first under CPU contention, producing a raw OperationCanceledException that bypasses the conversion. Both exception types correctly indicate the gather operation failed.

This change accepts either InvalidOperationException or OperationCanceledException as passing.

This change also disposes CancellationTokenSource instances.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • N/A [ ] Added tests
  • N/A [ ] Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

The test asserts that a primary source timeout throws
InvalidOperationException. GatherPackageAsync converts
OperationCanceledException to InvalidOperationException, but
cancellation checks in the main loop and worker task entry can fire
first under CPU contention, producing a raw OperationCanceledException
that bypasses the conversion. Both exception types correctly indicate
the gather operation failed.

Accept either InvalidOperationException or OperationCanceledException.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dtivel dtivel requested a review from a team as a code owner March 29, 2026 19:35
@dtivel dtivel requested review from donnie-msft and jebriede March 29, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: ResolverGather_TimeoutFromPrimaryRepositoryThrows is flaky under CPU contention

2 participants