diff --git a/test/js/bun/spawn/spawn-streaming-stdout.test.ts b/test/js/bun/spawn/spawn-streaming-stdout.test.ts index 07a70e1a14..ecee06798a 100644 --- a/test/js/bun/spawn/spawn-streaming-stdout.test.ts +++ b/test/js/bun/spawn/spawn-streaming-stdout.test.ts @@ -8,34 +8,40 @@ import { devNull } from "os"; test("spawn can read from stdout multiple chunks", async () => { gcTick(true); var maxFD: number = -1; - + let concurrency = 7; + const count = 100; const interval = setInterval(dumpStats, 1000); - for (let i = 0; i < 100; i++) { - await (async function () { - const proc = spawn({ - cmd: [bunExe(), import.meta.dir + "/spawn-streaming-stdout-repro.js"], - stdin: "ignore", - stdout: "pipe", - stderr: "ignore", - env: bunEnv, - }); - var chunks = []; - let counter = 0; - try { - for await (var chunk of proc.stdout) { - chunks.push(chunk); - counter++; - if (counter > 3) break; + for (let i = 0; i < count; ) { + const promises = new Array(concurrency); + for (let j = 0; j < concurrency; j++) { + promises[j] = (async function () { + const proc = spawn({ + cmd: [bunExe(), import.meta.dir + "/spawn-streaming-stdout-repro.js"], + stdin: "ignore", + stdout: "pipe", + stderr: "ignore", + env: bunEnv, + }); + var chunks = []; + let counter = 0; + try { + for await (var chunk of proc.stdout) { + chunks.push(chunk); + counter++; + if (counter > 3) break; + } + } catch (e: any) { + console.log(e.stack); + throw e; } - } catch (e: any) { - console.log(e.stack); - throw e; - } - expect(counter).toBe(4); - proc.kill(); - expect(Buffer.concat(chunks).toString()).toStartWith("Wrote to stdout\n".repeat(4)); - await proc.exited; - })(); + expect(counter).toBe(4); + proc.kill(); + expect(Buffer.concat(chunks).toString()).toStartWith("Wrote to stdout\n".repeat(4)); + await proc.exited; + })(); + } + await Promise.all(promises); + i += concurrency; if (maxFD === -1) { maxFD = openSync(devNull, "w"); closeSync(maxFD);