Skip to content

Make ADC rejected-create cancellation test deterministic - #21591

Merged
David Fowler (davidfowl) merged 2 commits into
mainfrom
aspireagent/fix-azure-devcompute-cancel-flake
Oct 31, 2026
Merged

David Fowler (davidfowl) merged 2 commits into
mainfrom
aspireagent/fix-azure-devcompute-cancel-flake

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes the intermittent Aspire.Hosting.Azure.Tests.AzureSandboxesTests.AzureDevComputeClientKeepsCancellationAfterRejectedCreateDefinite failure (Assert.False() Failure … Actual: True at AzureSandboxesTests.cs:1605).

Root cause: the test is meant to check that cancelling during the 403 retry delay is reported as a definite rejection (ResponseMayHaveBeenLost == false). It cancelled with a wall-clock CancellationTokenSource(TimeSpan.FromMilliseconds(10)). When that timer fired while the first HttpClient.SendAsync was still in flight (cold or slow runner), SendCoreAsync correctly classified the cancellation as ambiguous (ResponseMayHaveBeenLost = true), and the assertion failed. The product code is correct; the test raced a timer against the first round-trip.

Fix (test-only): cancel the token from the shared TestSink.MessageLogged callback (through TestLogger) when the client logs its 403-retry warning. That warning is emitted after the rejection is received and immediately before Task.Delay(retryDelay, token), so cancellation always lands in the retry delay. The fix adds no sleeps or retries, and the original assertions are unchanged. It also adds Assert.Equal(1, requestCount) to prove cancellation happened after exactly one definitive rejection.

Frequency: window 2026-10-29T11:16Z – 2026-10-31T10:38Z, 361 ci.yml runs. Latest attempts of Hosting.Azure (ubuntu-latest): 170 success, 13 failure, 17 cancelled.

  • This signature: 2 failures, both first attempts on main pushes: runs 41085859817 and 41004872500.
  • The other 11 failures were different signatures (8 × AzureFunctionsTests.AddAzureFunctionsProject_WorksWithMultipleProjects, 2 × PR snapshot mismatches, 1 × PR build error). Failures hidden behind successful reruns are not counted.

Repro evidence: I compiled the real AzureDevComputeClient.cs into a standalone harness, one fresh process per run.

Variant Result
Original test body (10ms timer) 20/20 FAIL: ResponseMayHaveBeenLost=True, TaskCanceledException, 1 request (the CI signature)
Fixed test body 20/20 PASS
Fixed test body, 403 response delayed by 200ms 20/20 PASS

CI on db5ec96: green. Hosting.Azure (ubuntu-latest) and Hosting.Azure (windows-latest), the jobs that run this test, passed on the first attempt, with no reruns.

Fixes #21589

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

The test cancelled with a 10ms wall-clock timeout, which could fire while
the first HTTP request was still in flight. The client then correctly
reported the cancellation as ambiguous (ResponseMayHaveBeenLost=true) and
the assertion failed. Cancel when the client logs its 403 retry warning
instead, so cancellation always lands in the retry delay after the
definite rejection.

Fixes #21589

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21591

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21591"

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 31, 2026
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test duplicates a private ILogger implementation instead of reusing the shared TestLogger and TestSink.MessageLogged callback, which preserves cancellation timing and follows the shared-test-dependency guidelines.

1 open issue
What changed in this PR

This test-only change addresses #21589 by making cancellation deterministic in the Azure Dev Compute rejected-create test. Production behavior is unchanged.

Changes:

  • Replaces the 10 ms cancellation timer with cancellation triggered by the 403-retry warning.
  • Adds an assertion that exactly one request occurred, while preserving the rejection-classification assertions.
File Description
tests/​Aspire.Hosting.Azure.Tests/​AzureSandboxesTests.cs Adds warning-triggered cancellation and verifies a single rejected request.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the test-only cancellation synchronization change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

2 / 100 PR test projects · 0 PR jobs, from 1 changed file.

Selected PR test projects (2 / 100)

Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Tests

Selected PR jobs (0)

none


How these were chosen — grouped by what changed

🧪 tests/Aspire.Hosting.Azure.Tests/AzureSandboxesTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Azure.Tests
→ 1 via the project graph: Aspire.Hosting.Azure.Kubernetes.Tests

Job reasons

none


Selection computed for commit db5ec96.

@davidfowl
David Fowler (davidfowl) merged commit 09065bb into main Oct 31, 2026
54 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 31, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → test_only. No signals triggered (signal_count == 0). The only changed file, tests/Aspire.Hosting.Azure.Tests/AzureSandboxesTests.cs, matches tests/**. This is a test-only deflake with no product code or user-facing changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: AzureSandboxesTests.AzureDevComputeClientKeepsCancellationAfterRejectedCreateDefinite races a 10ms timeout

3 participants