Skip to content

Fix WebSocket test double-done flake#150

Open
bghgary wants to merge 1 commit intoBabylonJS:mainfrom
bghgary:fix/websocket-test-flake
Open

Fix WebSocket test double-done flake#150
bghgary wants to merge 1 commit intoBabylonJS:mainfrom
bghgary:fix/websocket-test-flake

Conversation

@bghgary
Copy link
Copy Markdown
Contributor

@bghgary bghgary commented Apr 8, 2026

Fix intermittent CI flake in WebSocket tests (Win32_x64_JSI).

Root Cause

When the WebSocket connection to wss://ws.postman-echo.com/raw fails (network issue, rate limiting, service downtime), the onerror callback fires followed by onclose. Both called done(), causing mocha's "done() called multiple times" error and a test failure.

Fix

Guard done() with a finished flag via a finish() 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.

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>
Copilot AI review requested due to automatic review settings April 8, 2026 18:52
Copy link
Copy Markdown
Contributor

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 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 finished flag and finish() 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 calling done() 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"));
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
finish(new Error("Websocket failed"));
finish(new Error("WebSocket failed"));

Copilot uses AI. Check for mistakes.
Comment on lines 524 to 527

ws1.onerror = (ev) => {
done(new Error("Websocket failed"));
finish(new Error("Websocket failed"));
};
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants