Fix WebSocket polyfill spec compliance and test flake#150
Open
bghgary wants to merge 3 commits intoBabylonJS:mainfrom
Open
Fix WebSocket polyfill spec compliance and test flake#150bghgary wants to merge 3 commits intoBabylonJS:mainfrom
bghgary wants to merge 3 commits intoBabylonJS:mainfrom
Conversation
When the WebSocket connection fails, onerror fires followed by onclose. Both called done(), causing mocha's 'done() called multiple times' error. Guard done() with a finished flag so only the first callback completes the test. This fixes the intermittent CI flake on Win32_x64_JSI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent Mocha CI flake in the Win32_x64_JSI WebSocket unit tests by preventing done() from being invoked multiple times when onerror is followed by onclose.
Changes:
- Added a
finishedflag andfinish()wrapper to ensure only the first callback completes the test. - Updated both the single-connection and multiple-connection WebSocket tests to use
finish()instead of callingdone()directly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fix WebSocket polyfill and test flake.
Polyfill Fix
Per the WebSocket spec,
onclosemust always fire afteronerror. The polyfill'sErrorCallbackonly firedonerrorwithout triggering a close event. This caused tests to calldone()from bothonerrorandonclose(when the native layer fired close separately), resulting in mocha's "done() called multiple times" error.Changes:
ErrorCallbacknow callsCloseCallbackafter firingonerror, matching the specCloseCallbackis now idempotent (skips if already closed) so it's safe if the native layer also calls it separatelyTest Fix
With
oncloseguaranteed as the terminal event, tests now collect errors from earlier phases and report them inonclose—done()is called exactly once. No guard flags needed.Note
The tests still depend on an external WebSocket echo service (
ws.postman-echo.com). If the service is down, the tests will fail with "WebSocket failed" rather than crash with double-done.