Skip to content

test: wait for navigation to settle in loadURL tests - #51579

Merged
ckerr merged 1 commit into
mainfrom
fix/flaky-reentrant-loadurl-tests
May 15, 2026
Merged

ckerr merged 1 commit into
mainfrom
fix/flaky-reentrant-loadurl-tests

Conversation

@ckerr

@ckerr ckerr commented May 10, 2026 •

Copy link
Copy Markdown
Member

Description of Change

Followup to #51315, which was a partial fix but missed another way for these tests to break.

The three loadURL() tests could call done() while the primary navigation was still in-flight. When the second loadURL() call is rejected by the guard in WebContents::LoadURL(), it emits did-fail-load synchronously. If the test exits on did-fail-load alone, the afterEach() call to closeAllWindows() can destroy the window while that primary navigation still has in-flight events.

Fix by using Promise.all() to wait for both did-fail-load and did-stop-loading before the test exits, ensuring the primary navigation has fully settled.

Sample log of this failure, seen in a downstream CI run for v41.5.1 :

ok 415 webContents module loadURL() promise API fails if loadurl is called after the navigation is ready to commit
Unhandled exception in main spec runner: TypeError: Object has been destroyed
    at BrowserWindow.__webpack_modules__../lib/browser/api/browser-window.ts.BrowserWindow.loadURL (node:electron/js2c/browser_init:1069:17)
    at WebContents.<anonymous> (D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts:557:11)
    at Object.onceWrapper (node:events:634:26)
    at WebContents.emit (node:events:519:28)
ok 412 webContents module loadURL() promise API rejects when navigation is cancelled due to a bad scheme
ok 413 webContents module loadURL() promise API does not crash when loading a new URL with emulation settings set
ok 414 webContents module loadURL() promise API fails if loadURL is called inside did-start-loading
ok 415 webContents module loadURL() promise API fails if loadurl is called after the navigation is ready to commit
not ok 416 webContents module loadURL() promise API "after each" hook: closeAllWindows in "loadURL() promise API"
  done() called multiple times in hook <webContents module loadURL() promise API "after each" hook: closeAllWindows in "loadURL() promise API"> of file D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts; in addition, done() received error: TypeError: Object has been destroyed
      at BrowserWindow.__webpack_modules__../lib/browser/api/browser-window.ts.BrowserWindow.loadURL (node:electron/js2c/browser_init:1069:17)
      at WebContents.<anonymous> (D:\a\_work\1\b\src\electron\spec\api-web-contents-spec.ts:557:11)
      at Object.onceWrapper (node:events:634:26)
      at WebContents.emit (node:events:519:28) {
    uncaught: true
  }

Checklist

Release Notes

Notes: none

@ckerr
ckerr requested a review from a team May 10, 2026 18:15
@ckerr ckerr added semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. labels May 10, 2026

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tests added in https://github.com/electron/electron/pull/48004/changes with goal that we actually don't trigger a secondary navigation and abort earlier with the did-fail-load event, either the fix is incomplete or it should be incorrect that there is a secondary navigation from these tests. Could we confirm the source ?

@ckerr
ckerr force-pushed the fix/flaky-reentrant-loadurl-tests branch from 6f85824 to a7dc509 Compare May 14, 2026 19:07
@ckerr

ckerr commented May 14, 2026

Copy link
Copy Markdown
Member Author

Could we confirm the source ?

You're right, the secondary navigation was a red herring. Waiting for navigation to settle was still the right answer, but not for the reason I described. I've revised the branch and the PR description.

The three reentrant loadURL tests could call done() while the primary
navigation was still in-flight. When the reentrant loadURL call is
rejected by the guard in WebContents::LoadURL(), it emits did-fail-load
synchronously. If the test exits on did-fail-load alone, the afterEach()
call to closeAllWindows() can destroy the window while that primary
navigation still has in-flight events.

Fix by using Promise.all() to wait for both did-fail-load and
did-stop-loading before the test exits, ensuring the primary navigation
has fully settled. The tests are also converted from done-callback style
to async/await for clarity.

Co-authored-by: GitHub Copilot <[email protected]>
@ckerr
ckerr force-pushed the fix/flaky-reentrant-loadurl-tests branch from a7dc509 to c483daa Compare May 14, 2026 19:11

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

The PR description could use some update to match the latest commit description.

@ckerr ckerr changed the title test: wait for navigation to settle in reentrant loadURL tests test: wait for navigation to settle in loadURL tests May 15, 2026
@ckerr

ckerr commented May 15, 2026

Copy link
Copy Markdown
Member Author

The PR description could use some update to match the latest commit description.

Done.

I thought I'd done that yesterday, but apparently my mouse didn't find the "Update comment" button 😵

@ckerr
ckerr merged commit 7d8bc94 into main May 15, 2026
126 of 129 checks passed
@ckerr
ckerr deleted the fix/flaky-reentrant-loadurl-tests branch May 15, 2026 15:02
@release-clerk

release-clerk Bot commented May 15, 2026

Copy link
Copy Markdown

No Release Notes

@trop

trop Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "40-x-y", please check out #51641

@trop trop Bot removed the target/40-x-y PR should also be added to the "40-x-y" branch. label May 15, 2026
@trop

trop Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "41-x-y", please check out #51642

@trop

trop Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #51643

@trop

trop Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #51644

@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/40-x-y PR was merged to the "40-x-y" branch. and removed target/41-x-y PR should also be added to the "41-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/43-x-y in-flight/41-x-y in-flight/40-x-y labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

44-x-y merged/40-x-y PR was merged to the "40-x-y" branch. merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants