Repository navigation
Fix flaky MetricsTests exemplars dialog assertion - #21596
Merged
Mitch Denny (mitchdenny) merged 2 commits intoNov 3, 2026
Merged
Mitch Denny (mitchdenny) merged 2 commits into
Mitch Denny (mitchdenny) merged 2 commits into
Conversation
bUnit's Click() dispatches through the renderer dispatcher fire-and-forget. When ChartContainer's background update (a real 200ms PeriodicTimer) is rendering, the click is queued and Click() returns before the handler opens the dialog, so Assert.Single(dialogs) saw an empty collection. Signal when the dialog is shown and await it, and hold the renderer during the click so the test always covers the queued ordering. Fixes #21126 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21596Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21596" |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The metrics test can leave the renderer blocked and hang teardown if button lookup or clicking throws, so renderer release and holding-task cleanup need a finally block.
1 open issue
What changed in this PR
This test-only change addresses the flaky exemplars dialog assertion in dashboard metrics tests reported in #21126. It synchronizes assertions with dialog creation rather than assuming the click handler runs immediately.
Changes:
- Signals dialog creation through a
TaskCompletionSourceand awaits it with a timeout. - Holds the renderer dispatcher during the click to exercise the queued-event ordering deterministically.
| File | Description |
|---|---|
tests/Aspire.Dashboard.Components.Tests/Pages/MetricsTests.cs |
Adds dialog synchronization and deterministic dispatcher contention to the exemplars test. |
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 of 14 tasks
David Fowler (davidfowl)
marked this pull request as ready for review
October 31, 2026 15:25
Mitch Denny (mitchdenny)
approved these changes
Nov 3, 2026
Mitch Denny (mitchdenny)
left a comment
Member
There was a problem hiding this comment.
Reviewed the test synchronization and renderer cleanup. No actionable findings.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Description
Fixes a flaky test:
MetricsTests.ChartContainer_UnavailableHistogramPercentiles_TablePreservesExemplarssometimes fails withAssert.Single() Failure: The collection was emptyat theAssert.Single(dialogs)that follows the exemplars button click. Seen on Windows in runs 39212142055 and 39216025977.Root cause
This is a race in the test, not a product bug.
Click()is fire-and-forget. It callsTriggerEvent, which does_ = TriggerEventAsync(...)and dispatches throughrenderer.Dispatcher.InvokeAsync.ChartContainerruns a backgroundPeriodicTimerthat ticks every 200 ms in real time, because the test'sBrowserTimeProvideruses real timers. Each tick re-renders the chart and table throughInvokeAsync(StateHasChanged)from a thread-pool thread.Click()returns beforeMetricTable.OpenExemplarsDialogAsyncruns.Assert.Single(dialogs)then runs against an empty queue.ClickAsyncisn't an option here. The handler awaitsTestDialogService.ShowDialogAsync, which awaitsinstance.Result, and that only completes when the dialog closes.Fix
Test-only. The test's dialog callback now completes a
TaskCompletionSourcewhen the dialog is shown. The test awaits it (withDefaultTimeout) before asserting, so the assertion depends on the dialog actually being shown, not on when the click happens to run. There are no sleeps or retries, and the assertions are unchanged.To make the regression deterministic, the test holds the renderer dispatcher from another thread while it clicks, then releases it. This forces the "click queued behind a render" ordering on every run instead of only under CI load.
Evidence
Before: the old click-then-assert code with the dispatcher held fails all four theory cases with the exact CI signature:
After, all run locally on Linux:
MetricsTestspassed 5 out of 5 runs (42/42 each).Aspire.Dashboard.Components.Testsproject: 1161 passed, 0 failed.Fixes #21126
Checklist
🤖 Posted by AspireAgent (AI Agent)