diff options
author | 2023-01-26 18:26:05 -0800 | |
---|---|---|
committer | 2023-01-26 18:26:05 -0800 | |
commit | 44c6ce11c4cdf160caf445da64f52019ed810073 (patch) | |
tree | 6dfafe8155e562ab480094717ed89a4da39d7a24 /test/bun.js/websocket.test.js | |
parent | b32b0b87369c16e98c3402abb1d7ffd54c835f34 (diff) | |
download | bun-44c6ce11c4cdf160caf445da64f52019ed810073.tar.gz bun-44c6ce11c4cdf160caf445da64f52019ed810073.tar.zst bun-44c6ce11c4cdf160caf445da64f52019ed810073.zip |
fix websocket hang (#1910)
* ref and deref, and some tests
* subprocess file
* remove deref
* use flag in test
Diffstat (limited to 'test/bun.js/websocket.test.js')
-rw-r--r-- | test/bun.js/websocket.test.js | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/test/bun.js/websocket.test.js b/test/bun.js/websocket.test.js index ff5362050..0d4a0ce06 100644 --- a/test/bun.js/websocket.test.js +++ b/test/bun.js/websocket.test.js @@ -1,5 +1,7 @@ import { describe, it, expect } from "bun:test"; -import { unsafe } from "bun"; +import { unsafe, spawn, readableStreamToText } from "bun"; +import { bunExe } from "bunExe"; + import { gc } from "./gc"; const TEST_WEBSOCKET_HOST = @@ -131,3 +133,52 @@ describe("WebSocket", () => { gc(true); }); }); + +describe("websocket in subprocess", () => { + it("should exit", async () => { + let messageReceived = false; + const server = Bun.serve({ + port: 8765, + fetch(req, server) { + if (server.upgrade(req)) { + return; + } + + return new Response("http response"); + }, + websocket: { + open(ws) { + ws.send("hello websocket"); + }, + message(ws) { + messageReceived = true; + ws.close(); + }, + close(ws) {}, + }, + }); + const subprocess = Bun.spawn({ + cmd: [bunExe(), "websocket-subprocess.ts", server.hostname, server.port], + stderr: "pipe", + stdin: "pipe", + stdout: "pipe", + }); + + expect(await subprocess.exited).toBe(0); + expect(messageReceived).toBe(true); + server.stop(); + }); + + it("should exit after killed", async () => { + const subprocess = Bun.spawn({ + cmd: [bunExe(), "websocket-subprocess.ts", TEST_WEBSOCKET_HOST], + stderr: "pipe", + stdin: "pipe", + stdout: "pipe", + }); + + subprocess.kill(); + + expect(await subprocess.exited).toBe("SIGHUP"); + }); +}); |