Skip to content

Wait for tunnel health before asserting in ContainerTunnelTests - #20153

Merged
Mitch Denny (mitchdenny) merged 1 commit into
microsoft:mainfrom
afscrome:claude/aspire-test-failures-b40fc9
Sep 25, 2026
Merged

Mitch Denny (mitchdenny) merged 1 commit into
microsoft:mainfrom
afscrome:claude/aspire-test-failures-b40fc9

Conversation

@afscrome

@afscrome Alex Crome (afscrome) commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a race condition in Aspire.Hosting.Tests.ContainerTunnelTests that made ContainerTunnelWorksWithYarp and ProxylessEndpointWorksWithContainerTunnel potentially 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 HttpClient silently 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 like HttpRequestException: 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, WaitingContainersCanUseTunnel and HostResourceCanWaitForTunnelDependentContainers, already avoid this problem by waiting for KnownResourceStates.Running before 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 the yarp resource builder (checking the same route the test exercises)
  • await app.ResourceNotifications.WaitForResourceHealthyAsync(yarp.Resource.Name) before making the real assertion request

Now 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.csproj succeeds
  • CI run of Aspire.Hosting.Tests (these tests require TestFeature.ContainerRuntime/ContainerImageBuild, not exercisable in this sandbox without Docker)

🤖 Generated with Claude Code

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]>
@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 -- 20153

Or

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

@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 Sep 15, 2026
@mitchdenny
Mitch Denny (mitchdenny) merged commit 50cdaed into microsoft:main Sep 25, 2026
64 checks passed
@mitchdenny

Copy link
Copy Markdown
Member

Thanks Alex Crome (@afscrome)!

@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 14.0 milestone Sep 25, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 26, 2026
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.

2 participants