Repository navigation
Fix Windows test shutdown file lock failures - #20406
David Negstad (danegsta) wants to merge 4 commits into
Conversation
Use an independent teardown timeout for explicit-start tests and forward DCP diagnostics only after hosted services have stopped. Co-authored-by: Copilot App <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20406Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20406" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All reviewed changes are covered with no unresolved issues.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes Windows test shutdown failures caused by DCP diagnostic file locks and shared timeout budgets.
Changes:
- Moves DCP log forwarding to
StoppedAsync. - Adds independent teardown timeouts.
- Adds locked-file regression coverage.
| File | Description |
|---|---|
tests/Shared/DistributedApplicationTestingBuilderExtensions.cs |
Defers DCP log forwarding until hosted services stop. |
tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs |
Adds independent shutdown timeouts. |
tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs |
Verifies forwarding after file locks are released. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| using var shutdownCts = AsyncTestHelpers.CreateDefaultTimeoutTokenSource(TestConstants.DefaultOrchestratorTestLongTimeout); | ||
| await app.StopAsync(shutdownCts.Token).DefaultTimeout(TestConstants.DefaultOrchestratorTestLongTimeout); |
There was a problem hiding this comment.
Why is this needed? Why in only a couple of tests? Every test is calling StopAsync. What about setting a stop timeout on the host instead when programs are created? In other words, look for a way to make this automatically applied in every test.
There was a problem hiding this comment.
Updated to apply this more universally for anything using TestDistributedApplicationBuilder.
Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Configure a dedicated CI-scaled host shutdown budget and avoid reusing startup cancellation tokens during teardown. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
| public static readonly int ExtraLongTimeoutDuration = 60 * 1000 * 3 * (PlatformDetection.IsRunningOnCI ? 2 : 1); // 180 sec, 360 sec in CI -- useful when a docker image might need pulling | ||
| public static readonly int DefaultOrchestratorTestTimeout = 15 * 1000 * (PlatformDetection.IsRunningOnCI ? 2 : 1); // 15 sec, 30 sec in CI | ||
| public static readonly int DefaultOrchestratorTestLongTimeout = 45 * 1000 * (PlatformDetection.IsRunningOnCI ? 4 : 1); // 45 sec, 180 sec in CI | ||
| public static readonly int DefaultOrchestratorTestShutdownTimeout = 15 * 1000 * (PlatformDetection.IsRunningOnCI ? 3 : 1); // 15 sec, 45 sec in CI |
There was a problem hiding this comment.
Just use DefaultOrchestratorTestTimeout. Make it 45 sec in CI if required.
Want to avoid a lot of slightly different timeouts.
There was a problem hiding this comment.
I moved this into a deeper shared layer so it can apply more consistently, but it also makes using the shared constants harder. I think the current approach is a reasonable tradeoff.
| testProgram.AppBuilder.Services.Configure<HostOptions>(options => | ||
| options.ShutdownTimeout = TimeSpan.FromMilliseconds(TestConstants.DefaultOrchestratorTestShutdownTimeout)); |
There was a problem hiding this comment.
Does this actually fix the problem though? I was just throwing it out as an idea.
An error gets thrown when it hits the timeout, right? Won't that fail the test. These timeouts exist so tests don't hang, not to make them non-flaky.
There was a problem hiding this comment.
If tests are taking 30 seconds to shutdown it sounds like that is the problem that should be addressed, not making timeouts longer.
There was a problem hiding this comment.
We haven't touched DCP shutdown in quite some time; this is very likely CI contention. We can independently spend cycles looking if we can squeeze more shutdown performance out of DCP, but in general there's a floor dictated by our graceful shutdown attempts. Given that I've seen the affected tests failing itermitantly across several PRs recently, I'd argue bumping our shutdown timeout is a reasonable approach if it increases how often tests pass on the first run.
There was a problem hiding this comment.
Actually, that separate DCP investigation turned up an interesting candidate; basically under load the underlying k8s API server we're using can switch the order events are delivered. So the tests are potentially hanging because we never actually see that a resource was deleted: microsoft/dcp#275
Co-authored-by: Copilot App <[email protected]>
Tests selector40 / 99 PR test projects · 0 PR jobs, from 7 changed files. Selected PR test projects (40 / 99)
Selected PR jobs (0)none How these were chosen — grouped by what changed
🧪 show 34
🧪 🧪 🧪 🧪 🧪 Job reasonsnone Selection computed for commit |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
It has a compilation failure and unresolved shutdown-token and timeout-coverage issues.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Resolved since last review (1)
| public static class DistributedApplicationTestingBuilderExtensions | ||
| { | ||
| private static readonly TimeSpan s_defaultHostShutdownTimeout = | ||
| TimeSpan.FromSeconds(PlatformDetection.IsRunningOnCI ? 45 : 30); // 30 sec, 45 sec in CI |
There was a problem hiding this comment.
Just set to TestConstants.LongTimeoutTimeSpan
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
This may actually be a weird bug in our k8s API Server (see microsoft/dcp#275) |
|
Closing as the underlying issue was an out-of-order update bug in the DCP api server. |
…lation and process exit) (#21397) ## Description > **Update after merging `main` (2026-10-30):** #21360 has since landed on `main` with its own fix that gives this test a separate `stopCts` for `StopAsync` and moves it to `LongTimeoutTimeSpan` budgets. The cancellation-ownership repair this PR originally made is therefore already on `main`. After resolving the merge conflict, this PR adds **regression coverage only** on top of `main`'s version of the test: > > - The test becomes a `[Theory]` that also covers an explicitly cancelled startup token after startup has completed (`cancelStartupAfterStart: true`). > - The test awaits its actual `StartAsync` task instead of discarding it. > - It asserts that the ServiceB root process is running before shutdown and has exited afterwards, and that `ApplicationStopped` fires. > > The timeouts and token ownership come unchanged from `main`. The before/after evidence below was gathered against the original pre-#21360 base. It shows why phase-owned shutdown is needed, but it is no longer this PR's diff. Both theory cases pass locally on the merged head. Original description (pre-merge): give `BeforeResourceStartedEvent_NotFiredForExplicitStartOnInitialCreation` separate startup and shutdown cancellation budgets. A slow startup previously consumed most of the same 30-second CI token subsequently passed to `StopAsync`, causing cleanup cancellation even when shutdown itself completed within the standard bound. Related: #21026, #21328. These issues are intentionally left open for continued observation. The test now observes its actual startup task, creates the shutdown token only when entering shutdown, and runs both natural and explicitly cancelled completed-startup cases. All existing resource/event assertions, waits, ports, and timeout values are preserved. Both cases verify actual host shutdown and ServiceB root-process exit. No product, shared fixture, workflow, dependency, or policy changes are included. ### Native before/after evidence | Run | Actual selected execution evidence | |---|---| | [Unmodified baseline](https://github.com/microsoft/aspire/actions/runs/40903532956) | 8 passed / 1 failed. Failure was cancellation in the original line-365 `StopAsync` after approximately 21 seconds of startup consumed the shared 30-second budget. | | [Paired causal experiment](https://github.com/microsoft/aspire/actions/runs/40908555842) | Shared-token/cancelled-completed-startup controls failed 9/9; phase-owned shutdown with the same startup cancellation passed 9/9, with actual shutdown/root exit within the unchanged bound. Diagnostic controls and instrumentation are not in this PR. | | [Clean repair qualification](https://github.com/microsoft/aspire/actions/runs/40913395606) | **60 actual TRX executions passed, 0 failed, 0 skipped** on Windows runners 2 and 3, each completing all three fixed iterations. Includes both repaired rows six times each, 12 adjacent event cases, and 36 broader lifecycle/cancellation/explicit-start cases. | The clean repaired source at `d28c36fe8091ae1308fbf5691e36b71c3b51b0e2` is byte-identical to the test source executed at validation head `7c6ad6b7d8d99b06eea1224f853ea45f4ad5f822`. Only the separate validation branch contains workflow selection/TRX-capture configuration. **Qualification gap:** 90 executions were planned. Runner 1's build succeeded, but its check reports “The hosted runner lost communication with the server.” It retained neither logs nor TRX; its 30 planned outcomes are unknown, not passes or demonstrated test failures. That qualification workflow remains failed; subsequent normal PR CI does not fill those missing outcomes. Local native execution was unavailable after the prescribed restore failed with NU1900/NU1905 resolving configured NuGet audit metadata; the supported hosted Windows path was used without policy overrides. ### Normal PR CI status (2026-10-29 18:28 UTC) [Normal CI](https://github.com/microsoft/aspire/actions/runs/40922625873) executed both repaired theory rows and both adjacent event facts successfully on Windows and Ubuntu. Hosting-1 completed **28 passed / 0 failed / 0 skipped** on Windows and **63 passed / 0 failed / 0 skipped** on Ubuntu. Attempt 1 failed in the unchanged Ubuntu `AzureFunctionsTests.AddAzureFunctionsProject_WorksWithMultipleProjects` at its line-201 parameterless `host.StopAsync()` (`TaskCanceledException`, 32.300-second test; suite 2,109 passed / 1 failed / 5 skipped). That separate test does not use this PR's repaired method or startup token; its root cause remains unproven. The repository's automatic CI rerun started attempt 2 without a source change. Its Azure suite passed **2,110 / 0 failed / 5 skipped**, including that method in 28.566 seconds. The macOS ARM64 build also succeeded. Latest applicable CI is now green on `d28c36fe8091ae1308fbf5691e36b71c3b51b0e2` (46 successful checks, 29 skipped); skipped checks are not passing test executions. The first Azure failure and the separate qualification gap above remain part of the evidence. Copilot review identified no active issues. This is ready for human review, not approved for merge. ### Scope and limits This is not a revival of #20406's broad shared-fixture/shutdown-timeout/DCP-log-forwarding changes. That PR was closed after an out-of-order DCP API-server update bug was identified. Here the actual selected host path separately demonstrates that passing an already-cancelled completed-startup token to shutdown causes cancellation; giving shutdown its own unchanged budget completes host shutdown and root exit. The distinct original line-353 resource-startup failure associated with Docker/WSLc discovery stalls is **not fixed or claimed fixed**. Root-process exit does not prove that every descendant process exited. Created using the repository's [fix-flaky-test skill](https://github.com/microsoft/aspire/blob/main/.agents/skills/fix-flaky-test/SKILL.md), with existing before/after native evidence and deterministic cancellation coverage rather than arbitrary delays or larger timeouts. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - If yes, did you have an API Review for it? - [ ] Yes - [ ] No - Did you add `<remarks />` and `<code />` elements on your triple slash comments? - [ ] Yes - [ ] No - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - If yes, have you done a threat model and had a security review? - [ ] Yes - [ ] No - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <[email protected]> Co-authored-by: Copilot <[email protected]>


Description
Windows test runs can take long enough to stop DCP-managed child processes that a timeout shared with startup expires during teardown. DCP diagnostic forwarding also ran before the orchestrator stopped those processes, so the diagnostic files could still be exclusively locked when the test tried to read them.
This change stops reusing startup and resource-operation cancellation tokens during teardown. Standard repository test builders and
TestProgramfixtures now preserve Generic Host's 30-second local shutdown budget while allowing 45 seconds on slower CI machines. DCP diagnostic forwarding runs fromIHostedLifecycleService.StoppedAsync, after all hosted services completeStopAsync, so Windows processes have released their diagnostic files before the tests read them.A focused regression test holds a DCP log open during
StopAsyncand verifies that it is forwarded only duringStoppedAsync.Validation:
DcpLogForwarderReadsLogsAfterHostedServicesStopBeforeResourceStartedEvent_NotFiredForExplicitStartOnInitialCreationBeforeResourceStartedEvent_FiredWhenExplicitStartResourceIsManuallyStartedBeforeResourceStartedEvent_FiredForNormalResourcesOnInitialStartupVerifyWithHttpHealthCheckBlocksDependentResourcesParentProcessLifetimeReusesResourcesAcrossAppRestartsAndStopsWhenParentExitsFixes #15223
Checklist
<remarks />and<code />elements on your triple slash comments?