Skip to content

Conversation

oroztocil
Copy link
Member

The quarantined test was flaky due to a race condition. The assert failed when the test driver did not manage to change the URL in time.

I used a script to execute the test in a loop (on an M2 Mac):

  • Before the change the test failed in 44/300 runs.
  • After the change the test failed in 0/300 runs.

Fixes #62533

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 14:17
@oroztocil oroztocil requested a review from a team as a code owner August 22, 2025 14:17
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

This PR fixes a race condition in the EventTest.PreventDefault_DoNotApplyByDefault test that was causing flaky test failures. The test was quarantined due to intermittent failures when the browser didn't complete the URL navigation in time for the assertion.

Key changes:

  • Removes the quarantine attribute and fixes test name typo
  • Replaces immediate assertion with WebDriverWait to handle timing issues
  • Adds explanatory comment for the expected behavior

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Aug 22, 2025
Comment on lines 286 to 288
// The URL should change because the submit event is not prevented
var wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(3));
wait.Until(driver => driver.Url.Contains("about:blank"));
Copy link
Member

Choose a reason for hiding this comment

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

Check the extensions on Browser they centralize things like the wait times and stuff like that, it might be better to use those.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I looked into the existing extensions and did not find one that would cover this kind of wait, so I added one. Is it ok like this?

@@ -284,8 +284,7 @@ public void PreventDefault_DoNotApplyByDefault()
appElement.FindElement(By.Id("form-2-button")).Click();

// The URL should change because the submit event is not prevented
var wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(3));
wait.Until(driver => driver.Url.Contains("about:blank"));
Browser.WaitForUrlToContain("about:blank");
Copy link
Member

Choose a reason for hiding this comment

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

I think so? But you can also search for Browser.Url usages and you might find an existing pattern.

Copy link
Member Author

@oroztocil oroztocil Aug 22, 2025

Choose a reason for hiding this comment

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

Ok, there should be implicit waits for this with 'Browser.Contains' or 'Browser.True'. (I see now what extensions you meant.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted the unneeded extension method.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Another suggestion, but that's it

@oroztocil oroztocil merged commit 963ca78 into main Aug 23, 2025
29 checks passed
@oroztocil oroztocil deleted the oroztocil/62533-fix-test-PreventDefault_DoNotApplyByDefault branch August 23, 2025 12:27
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Aug 23, 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 Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests.ServerEventTest.PreventDefault_DotNotApplyByDefault
2 participants