diff options
author | 2022-11-23 21:31:38 -0800 | |
---|---|---|
committer | 2022-11-23 21:31:38 -0800 | |
commit | bddf484c2c7c8d3aadf715f0d908516ed45caeeb (patch) | |
tree | ee7ce4eeb80b44dd44c112bf0af7bfc176f68185 /test/bun.js/spawn-streaming-stdin.test.ts | |
parent | 21531f1e80327f3c64e17fb3069c6bb38e8aad0c (diff) | |
download | bun-bddf484c2c7c8d3aadf715f0d908516ed45caeeb.tar.gz bun-bddf484c2c7c8d3aadf715f0d908516ed45caeeb.tar.zst bun-bddf484c2c7c8d3aadf715f0d908516ed45caeeb.zip |
Close the streams more
Diffstat (limited to 'test/bun.js/spawn-streaming-stdin.test.ts')
-rw-r--r-- | test/bun.js/spawn-streaming-stdin.test.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts new file mode 100644 index 000000000..953548071 --- /dev/null +++ b/test/bun.js/spawn-streaming-stdin.test.ts @@ -0,0 +1,53 @@ +import { it, test, expect } from "bun:test"; +import { spawn } from "bun"; +import { bunExe } from "./bunExe"; +import { gcTick } from "gc"; + +const N = 100; +test("spawn can write to stdin multiple chunks", async () => { + for (let i = 0; i < N; i++) { + var exited; + await (async function () { + const proc = spawn({ + cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"], + stdout: "pipe", + stdin: "pipe", + stderr: "inherit", + env: { + BUN_DEBUG_QUIET_LOGS: 1, + }, + }); + exited = proc.exited; + var counter = 0; + var inCounter = 0; + const prom2 = (async function () { + while (inCounter++ < 4) { + await new Promise((resolve, reject) => setTimeout(resolve, 8)); + proc.stdin.write("Wrote to stdin!"); + await proc.stdin.flush(); + } + await proc.stdin.end(); + })(); + + const prom = (async function () { + try { + for await (var chunk of proc.stdout) { + expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdin!\n"); + counter++; + + if (counter > 3) break; + } + } catch (e) { + console.log(e.stack); + throw e; + } + })(); + await Promise.all([prom, prom2]); + expect(counter).toBe(4); + // proc.kill(); + })(); + await exited; + } + + gcTick(true); +}); |