Repository navigation
Wait for tunnel health before asserting in ContainerTunnelTests - #20153
Merged
Mitch Denny (mitchdenny) merged 1 commit intoSep 25, 2026
Merged
Mitch Denny (mitchdenny) merged 1 commit into
Mitch Denny (mitchdenny) merged 1 commit into
Conversation
PR microsoft#18963 disabled the standard resilience handler in test builders, which exposed that ContainerTunnelWorksWithYarp and ProxylessEndpointWorksWithContainerTunnel relied on HTTP client retries to mask the yarp/tunnel container not being ready yet. Add a test-scoped health check on the yarp resource (Yarp has no built-in one) and wait for it before issuing the real request. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Alex Crome (afscrome)
requested a review
from Mitch Denny (mitchdenny)
as a code owner
September 15, 2026 19:54
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 20153Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 20153" |
6 tasks
Mitch Denny (mitchdenny)
approved these changes
Sep 25, 2026
Member
|
Thanks Alex Crome (@afscrome)! |
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.
Summary
Fixes a race condition in
Aspire.Hosting.Tests.ContainerTunnelTeststhat madeContainerTunnelWorksWithYarpandProxylessEndpointWorksWithContainerTunnelpotentially flaky.The problem
Both tests waited only for the
"Application started."log line before immediately issuing an HTTP request through the YARP tunnel. That log line only indicates the AppHost process is up — it says nothing about whether the YARP container (which may still be building/starting the tunnel proxy image) is actually ready to accept connections.The tests only passed because the standard resilience handler on the test
HttpClientsilently retried the first few failed connection attempts while the container finished starting. That's a race between "how long the container takes to become ready" and "how many retries/how much time the resilience handler allows" — on a slower or more loaded CI runner, or if the container takes a bit longer to start, the retries can be exhausted before the tunnel is ready, and the test fails with something likeHttpRequestException: The response ended prematurely. This is exactly the kind of latent, timing-dependent flakiness that shouldn't depend on a client-side retry policy to paper over.This surfaced concretely in #18963, an experiment that disables the resilience handler in test builders — with retries removed, both tests failed reliably, confirming they had no real readiness guarantee to begin with.
The other two tests in this file,
WaitingContainersCanUseTunnelandHostResourceCanWaitForTunnelDependentContainers, already avoid this problem by waiting forKnownResourceStates.Runningbefore proceeding.Fix
Replace the race with a deterministic readiness check. Yarp resources don't come with a built-in health check, so this adds one scoped to these tests:
.WithHttpHealthCheck("/servicea/")on theyarpresource builder (checking the same route the test exercises)await app.ResourceNotifications.WaitForResourceHealthyAsync(yarp.Resource.Name)before making the real assertion requestNow the test only proceeds once the tunnel has actually proven it can route a request through to
servicea, regardless of how long that takes or whether a resilience handler is configured.Test plan
dotnet build tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csprojsucceedsAspire.Hosting.Tests(these tests requireTestFeature.ContainerRuntime/ContainerImageBuild, not exercisable in this sandbox without Docker)🤖 Generated with Claude Code