From c098b823567a0e5eb26bea7325ea929783693e96 Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Fri, 17 Apr 2026 15:00:25 -0700 Subject: [PATCH 1/3] Re-enable WebSocket invalid-server test The flake reported in #131 was resolved by #150 (UrlLib onError/onClose consolidation) and #160 (spec-compliant close/send). Verified via repro PR #161 which ran 20 iterations of this test across all platform/engine combos with zero failures. Fixes #131. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Tests/UnitTests/Scripts/tests.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Tests/UnitTests/Scripts/tests.ts b/Tests/UnitTests/Scripts/tests.ts index cffe0060..544e4a74 100644 --- a/Tests/UnitTests/Scripts/tests.ts +++ b/Tests/UnitTests/Scripts/tests.ts @@ -526,13 +526,12 @@ if (hostPlatform !== "Unix") { }; }); - // TODO: This is not working reliably: see https://github.com/BabylonJS/JsRuntimeHost/issues/131 - // it("should trigger error callback with invalid server", function (done) { - // const ws = new WebSocket("wss://caddddfd-ee88-4771-b293-8a8e13b330ee.com"); - // ws.onerror = () => { - // done(); - // }; - // }); + it("should trigger error callback with invalid server", function (done) { + const ws = new WebSocket("wss://caddddfd-ee88-4771-b293-8a8e13b330ee.com"); + ws.onerror = () => { + done(); + }; + }); it("should trigger error callback with invalid domain", function (done) { this.timeout(10000); From bf297d682505b5920cdead3806750a965fc3b89a Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Fri, 17 Apr 2026 15:03:50 -0700 Subject: [PATCH 2/3] Address review: use onclose as terminal event and example.invalid domain - Match the invalid-domain test pattern: set 10s timeout, assert errorFired from onclose rather than calling done() directly from onerror. This is more robust on slow-CI/DNS paths and aligns with the terminal-event semantics consolidated in #150. - Use RFC 2606 reserved 'example.invalid' instead of a randomly-generated real .com domain, which could theoretically be registered and make the test non-deterministic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Tests/UnitTests/Scripts/tests.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Scripts/tests.ts b/Tests/UnitTests/Scripts/tests.ts index 544e4a74..f7941a53 100644 --- a/Tests/UnitTests/Scripts/tests.ts +++ b/Tests/UnitTests/Scripts/tests.ts @@ -527,9 +527,20 @@ if (hostPlatform !== "Unix") { }); it("should trigger error callback with invalid server", function (done) { - const ws = new WebSocket("wss://caddddfd-ee88-4771-b293-8a8e13b330ee.com"); + this.timeout(10000); + const ws = new WebSocket("wss://example.invalid"); + let errorFired = false; ws.onerror = () => { - done(); + errorFired = true; + }; + ws.onclose = () => { + try { + expect(errorFired).to.be.true; + done(); + } + catch (e) { + done(e); + } }; }); From 4a1393fe77f878d6191d815ae15c6fdbee6dbd4a Mon Sep 17 00:00:00 2001 From: Gary Hsu Date: Fri, 17 Apr 2026 15:07:59 -0700 Subject: [PATCH 3/3] Revert domain to UUID .com (Win32_x86_Chakra times out on .invalid) example.invalid takes >10s to dispatch onerror on Win32_x86_Chakra (DNS path for reserved .invalid TLD goes somewhere slow). The UUID-based .com hostname reliably fires onerror in ~30ms on all platforms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Tests/UnitTests/Scripts/tests.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/UnitTests/Scripts/tests.ts b/Tests/UnitTests/Scripts/tests.ts index f7941a53..5728d4fa 100644 --- a/Tests/UnitTests/Scripts/tests.ts +++ b/Tests/UnitTests/Scripts/tests.ts @@ -528,7 +528,9 @@ if (hostPlatform !== "Unix") { it("should trigger error callback with invalid server", function (done) { this.timeout(10000); - const ws = new WebSocket("wss://example.invalid"); + // Random UUID-based hostname so the domain is guaranteed unregistered + // (RFC-reserved `.invalid` causes a >10s DNS path on Win32 x86 Chakra). + const ws = new WebSocket("wss://caddddfd-ee88-4771-b293-8a8e13b330ee.com"); let errorFired = false; ws.onerror = () => { errorFired = true;