From 931ba9ad499838d831d08c8bbac4aa132e8aa0f7 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 2 Dec 2022 00:23:29 -0800 Subject: Add file descriptor leak test --- test/bun.js/spawn-streaming-stdin.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'test/bun.js/spawn-streaming-stdin.test.ts') diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts index 2285c50d2..a71a0e2a9 100644 --- a/test/bun.js/spawn-streaming-stdin.test.ts +++ b/test/bun.js/spawn-streaming-stdin.test.ts @@ -2,9 +2,11 @@ import { it, test, expect } from "bun:test"; import { spawn } from "bun"; import { bunExe } from "./bunExe"; import { gcTick } from "gc"; +import { closeSync, openSync } from "fs"; const N = 100; test("spawn can write to stdin multiple chunks", async () => { + const maxFD = openSync("/dev/null", "w"); for (let i = 0; i < N; i++) { var exited; await (async function () { @@ -47,10 +49,14 @@ test("spawn can write to stdin multiple chunks", async () => { expect(Buffer.concat(chunks).toString().trim()).toBe( "Wrote to stdin!\n".repeat(4).trim(), ); - // proc.kill(); - - gcTick(true); - await 1; + await proc.exited; })(); } + + closeSync(maxFD); + const newMaxFD = openSync("/dev/null", "w"); + closeSync(newMaxFD); + + // assert we didn't leak any file descriptors + expect(newMaxFD).toBe(maxFD); }); -- cgit v1.2.3