diff options
author | 2023-01-02 12:24:23 +0200 | |
---|---|---|
committer | 2023-01-02 02:24:23 -0800 | |
commit | 04b00229cf2408d4af742cb4cc890fd76c4fad1b (patch) | |
tree | c4acccebe3b3d01f9c3cdaa8778786ad67f14678 /test/bun.js/socket/socket.test.ts | |
parent | 8a29c643025c73312da001c5fa4caf0ccf0528fa (diff) | |
download | bun-04b00229cf2408d4af742cb4cc890fd76c4fad1b.tar.gz bun-04b00229cf2408d4af742cb4cc890fd76c4fad1b.tar.zst bun-04b00229cf2408d4af742cb4cc890fd76c4fad1b.zip |
fix lingering process by dead sockets (#1700)
`Bun.listen()` and `Bun.connect()` would create sockets that under certain conditions with calls to `.end()` or `.stop`, prevents the process from exiting gracefully.
Diffstat (limited to 'test/bun.js/socket/socket.test.ts')
-rw-r--r-- | test/bun.js/socket/socket.test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/bun.js/socket/socket.test.ts b/test/bun.js/socket/socket.test.ts new file mode 100644 index 000000000..aff001c75 --- /dev/null +++ b/test/bun.js/socket/socket.test.ts @@ -0,0 +1,34 @@ +import { expect, it } from "bun:test"; +import { bunExe } from "../bunExe"; +import { spawn } from "bun"; + +it("should keep process alive only when active", async () => { + const { exited, stdout, stderr } = spawn({ + cmd: [ bunExe(), "echo.js" ], + cwd: import.meta.dir, + stdout: "pipe", + stdin: null, + stderr: "pipe", + env: { + BUN_DEBUG_QUIET_LOGS: 1, + }, + }); + expect(await exited).toBe(0); + expect(await new Response(stderr).text()).toBe(""); + var lines = (await new Response(stdout).text()).split(/\r?\n/); + expect(lines.filter(function(line) { + return line.startsWith("[Server]"); + })).toEqual([ + "[Server] OPENED", + "[Server] GOT request", + "[Server] CLOSED", + ]); + expect(lines.filter(function(line) { + return line.startsWith("[Client]"); + })).toEqual([ + "[Client] OPENED", + "[Client] GOT response", + "[Client] ENDED", + "[Client] CLOSED", + ]); +}); |