Skip to content

Fix bUnit JS timeout flakes in StructuredLogs/Traces/TraceDetails tests - #21503

Open
David Fowler (davidfowl) wants to merge 1 commit into
mainfrom
aspireagent/fix-telemetry-page-js-results
Open

David Fowler (davidfowl) wants to merge 1 commit into
mainfrom
aspireagent/fix-telemetry-page-js-results

Conversation

@davidfowl

Copy link
Copy Markdown
Collaborator

Description

Fixes an intermittent Dashboard.Components flake: EmptyState_HelpDisappearsAfterAnySignalAndStaysHiddenAfterClear (StructuredLogs/Traces), plus TraceDetails tests, fail with Bunit.JSRuntimeInvocationNotSetException on slow runners (mostly Windows).

Root cause

In bUnit 2.x, a planned JS handler without a result leaves the invocation pending. After BunitContext.DefaultWaitTimeout (10s, set in DashboardPageTestContext), bUnit faults the invocation. That fault surfaces from the component's OnAfterRenderAsync and is rethrown by the next WaitForAssertion. So any test still running 10s after the first render fails.

Two kinds of handlers were left without a result:

  • focusElement: StructuredLogsTests, TracesTests and TraceDetailsTests each call JSInterop.SetupVoid("focusElement", _ => true) without a result. They do this after SetupFluentMenu registered a resolved handler. The last registration wins, so the resolved handler is overridden. Each page awaits focusElement(<scrollContainer>, true) on first render.
  • Tooltip: AddCommonDashboardServices registers the Tooltip module's FluentTooltipInitialize without a result.

This is the same bug class #21412 fixed for Select.Initialize and observeAttributeChange, and #21434 fixes in ManageDataDialogTests. This PR doesn't touch those files.

Fix

Add .SetVoidResult() to the four handlers. Test-only change.

CI evidence (attempt-1 failures, ci.yml, about Oct 16–31)

Survey: 1000 ci.yml runs (466 with Dashboard jobs). Dashboard.Components had 10 attempt-1 failures in 181 Windows jobs and 1 in 181 Ubuntu jobs. These 3 jobs failed on pending calls this PR fixes:

Run / job Head Failing tests Pending invocation
main push 40534267321 (Windows) b1b850f StructuredLogsTests.EmptyState… (and MetricsTests.EmptyState… on Select.Initialize, fixed since by #21412) focusElement("structuredLogsScrollContainer", true)
PR 40563038552 (Windows) and job 122398564683 (Ubuntu) f1cc41e TraceDetailsTests.ExpandAllSpans…, Render_TraceUpdateWithNewSpans…, ToggleCollapse… focusElement("traceDetailScrollContainer", true), FluentTooltipInitialize (plus handlers since fixed on main)

A fourth job, PR run 40390542875 (StructuredLogsTests.EmptyState… on Windows), faulted on observeAttributeChange, which #21412 has since fixed. On the same head the Ubuntu job passed. Locally, the 9 EmptyState cases passed 15/15 loops on main because they finish well under 10s. The other 6 Components failures were the MetricsTests histogram test (tracked separately in #21394).

Before/after

Slow-runner simulation (not committed). Added await Task.Delay(11s) before the final WaitForAssertion in the StructuredLogs/Traces EmptyState tests:

EmptyState (9 cases) Failure
main 6 failed / 9 JSRuntimeInvocationNotSetException: focusElement("structuredLogsScrollContainer"/"tracesScrollContainer", true) ×5, FluentTooltipInitialize ×1
this PR 9 passed / 9 n/a

Committed regression tests. These run fast and need no waits. Each replays the page's first-render JS call through the configured bUnit runtime and asserts the call completed immediately:

  • StructuredLogsTests.Setup_FirstRenderFocusInvocationCompletes
  • TracesTests.Setup_FirstRenderFocusInvocationCompletes
  • TracesTests.Setup_TooltipInitializeInvocationCompletes
  • TraceDetailsTests.Setup_FirstRenderFocusInvocationCompletes
Result
without the fix 4/4 fail (Assert.True() Failure)
with the fix 4/4 pass

Validation

  • Aspire.Dashboard.Components.Tests full suite: 1165 passed, 0 failed.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

🤖 Posted by AspireAgent (AI Agent)

StructuredLogs, Traces and TraceDetails test setups re-registered focusElement
without a result, overriding the resolved handler from SetupFluentMenu. The
tooltip initialize module handler also had no result. bUnit faults pending
planned invocations after DefaultWaitTimeout (10s), so slow CI runs failed
with JSRuntimeInvocationNotSetException.

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 -- 21503

Or

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

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

1 / 100 PR test projects · 0 PR jobs, from 4 changed files.

Selected PR test projects (1 / 100)

Aspire.Dashboard.Components.Tests

Selected PR jobs (0)

none


How these were chosen — grouped by what changed

🧪 tests/Aspire.Dashboard.Components.Tests/Pages/StructuredLogsTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

🧪 tests/Aspire.Dashboard.Components.Tests/Pages/TraceDetailsTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

🧪 tests/Aspire.Dashboard.Components.Tests/Pages/TracesTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

🧪 tests/Aspire.Dashboard.Components.Tests/Shared/FluentUISetupHelpers.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

Job reasons

none


Selection computed for commit 7db20db.

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 remain for the test-only changes that complete pending JavaScript interop mocks.

No open issues 🎉

What changed in this PR

This test-only change addresses intermittent bUnit JavaScript interop timeouts in Dashboard component tests by completing mock invocations that previously remained pending. Production dashboard behavior is unchanged.

Changes:

  • Add .SetVoidResult() to the three page-specific focusElement handlers and shared tooltip initialization handler.
  • Add four regression tests that verify these configured JavaScript calls complete immediately, without timeout-based waits.
File Description
tests/​Aspire.Dashboard.Components.Tests/​Shared/​FluentUISetupHelpers.cs Complete the shared tooltip initialization handler.
tests/​Aspire.Dashboard.Components.Tests/​Pages/​TracesTests.cs Complete the focus handler and add focus and tooltip regression tests.
tests/​Aspire.Dashboard.Components.Tests/​Pages/​TraceDetailsTests.cs Complete the focus handler and add a focus regression test.
tests/​Aspire.Dashboard.Components.Tests/​Pages/​StructuredLogsTests.cs Complete the focus handler and add a focus regression test.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants