Skip to content

Conversation

oroztocil
Copy link
Member

@oroztocil oroztocil commented Sep 11, 2025

Un-quarantines the ServerRenderingTests.FormHandlingTests.CanUseAntiforgeryAfterInitialRender test and attempts to fix its flakiness.

There seems to be a race condition due to which the result element can get re-rerendered between when we acquire a WebElement reference to it (using the Browser.Exists method) and when we read the element's text value. When that happens, StaleElementReferenceException is thrown. The PR tries to remove the flakiness by wrapping the access in a try/catch block in a Browser.True assertion, effectively adding a retry mechanism.

The test currently has no failures in the last 30 days on the quarantined test CI report. However, I have observe StaleElementReferenceException related failures when running the test locally in a loop (roughly 1 failure per 500 runs). With the PR change, the test has not failed in 3000 runs.

Fixes #57766

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Sep 11, 2025
@oroztocil oroztocil marked this pull request as ready for review September 11, 2025 13:49
@oroztocil oroztocil requested a review from a team as a code owner September 11, 2025 13:49
@Copilot Copilot AI review requested due to automatic review settings September 11, 2025 13:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes a flaky E2E test by addressing a race condition that caused StaleElementReferenceException when reading element text. The fix replaces a direct element access pattern with a retry mechanism to handle cases where the element gets re-rendered between acquiring the WebElement reference and reading its text value.

  • Removes the [QuarantinedTest] attribute to re-enable the test
  • Wraps element access in a try-catch block within a Browser.True assertion for automatic retries
  • Addresses the StaleElementReferenceException race condition

@oroztocil
Copy link
Member Author

oroztocil commented Sep 11, 2025

@ilonatommy I combined the interactive rendering condition in the component with a simplified retrying assertion in the test itself. If I get 3k successful runs (my arbitrary benchmark), I would merge it like this.

@oroztocil
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17649932628

@ilonatommy ilonatommy merged commit 2b18d5b into main Sep 12, 2025
30 checks passed
@ilonatommy ilonatommy deleted the oroztocil/57766-CanUseAntiforgeryAfterInitialRender-flake branch September 12, 2025 08:25
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quarantine CanUseAntiforgeryAfterInitialRender
3 participants