summaryrefslogtreecommitdiff
path: root/cli/tests/unit/websocket_test.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-04-21 12:25:02 +0530
committerGitHub <noreply@github.com>2023-04-21 08:55:02 +0200
commit4e944dea1d6ad6cc819cbef278b59923eeaa2287 (patch)
tree58a517e585478581ff2a4af99b8f203f4d876907 /cli/tests/unit/websocket_test.ts
parent1976504c632c78aaadbf24dc94e8ce5626bce9f1 (diff)
fix(ext/websocket): upgrade fastwebsockets to 0.2.4 (#18791)
Fixes https://github.com/denoland/deno/issues/18775
Diffstat (limited to 'cli/tests/unit/websocket_test.ts')
-rw-r--r--cli/tests/unit/websocket_test.ts51
1 files changed, 50 insertions, 1 deletions
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index 948e2add2..997d8f0df 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -1,5 +1,11 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assertEquals, assertThrows, deferred, fail } from "./test_util.ts";
+import {
+ assert,
+ assertEquals,
+ assertThrows,
+ deferred,
+ fail,
+} from "./test_util.ts";
Deno.test({ permissions: "none" }, function websocketPermissionless() {
assertThrows(
@@ -82,3 +88,46 @@ Deno.test(
ws.close();
},
);
+
+// https://github.com/denoland/deno/issues/18775
+Deno.test({
+ sanitizeOps: false,
+ sanitizeResources: false,
+}, async function websocketDoubleClose() {
+ const promise = deferred();
+
+ const ac = new AbortController();
+ const listeningPromise = deferred();
+
+ const server = Deno.serve({
+ handler: (req) => {
+ const { response, socket } = Deno.upgradeWebSocket(req);
+ let called = false;
+ socket.onopen = () => socket.send("Hello");
+ socket.onmessage = () => {
+ assert(!called);
+ called = true;
+ socket.send("bye");
+ socket.close();
+ };
+ socket.onclose = () => ac.abort();
+ socket.onerror = () => fail();
+ return response;
+ },
+ signal: ac.signal,
+ onListen: () => listeningPromise.resolve(),
+ hostname: "localhost",
+ port: 4247,
+ });
+
+ await listeningPromise;
+
+ const ws = new WebSocket("ws://localhost:4247/");
+ assertEquals(ws.url, "ws://localhost:4247/");
+ ws.onerror = () => fail();
+ ws.onmessage = () => ws.send("bye");
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await Promise.all([promise, server]);
+});