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>
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.
|
|
||
| ws2.onerror = (ev) => { | ||
| done(new Error("Websocket failed")); | ||
| finish(new Error("Websocket failed")); |
There was a problem hiding this comment.
Error message uses inconsistent capitalization ("Websocket failed") compared to the earlier test ("WebSocket failed"). For consistency and easier log filtering/grepping, consider standardizing on "WebSocket failed" (and/or include which socket failed: ws1 vs ws2).
| finish(new Error("Websocket failed")); | |
| finish(new Error("WebSocket failed")); |
|
|
||
| ws1.onerror = (ev) => { | ||
| done(new Error("Websocket failed")); | ||
| finish(new Error("Websocket failed")); | ||
| }; |
There was a problem hiding this comment.
Error message uses inconsistent capitalization ("Websocket failed") compared to the other WebSocket test ("WebSocket failed"). Consider standardizing the spelling/casing to avoid confusion in CI logs.
Fix intermittent CI flake in WebSocket tests (Win32_x64_JSI).
Root Cause
When the WebSocket connection to
wss://ws.postman-echo.com/rawfails (network issue, rate limiting, service downtime), theonerrorcallback fires followed byonclose. Both calleddone(), causing mocha's "done() called multiple times" error and a test failure.Fix
Guard
done()with afinishedflag via afinish()wrapper so only the first callback completes the test. Applied to both single and multiple connection tests.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. A more robust solution would use a local echo server, but that's a larger change.