Fix and un-quarantine CanUseAntiforgeryAfterInitialRender test#63640
Merged
ilonatommy merged 2 commits intomainfrom Sep 12, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.Trueassertion for automatic retries - Addresses the
StaleElementReferenceExceptionrace condition
javiercn
reviewed
Sep 11, 2025
src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/AntiforgeryTests.cs
Outdated
Show resolved
Hide resolved
javiercn
approved these changes
Sep 11, 2025
Member
Author
|
@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. |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17649932628 |
11 tasks
ilonatommy
approved these changes
Sep 12, 2025
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.
Un-quarantines the
ServerRenderingTests.FormHandlingTests.CanUseAntiforgeryAfterInitialRendertest and attempts to fix its flakiness.There seems to be a race condition due to which the
resultelement can get re-rerendered between when we acquire aWebElementreference to it (using theBrowser.Existsmethod) and when we read the element's text value. When that happens,StaleElementReferenceExceptionis thrown. The PR tries to remove the flakiness by wrapping the access in a try/catch block in aBrowser.Trueassertion, 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
StaleElementReferenceExceptionrelated 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