mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 05:12:29 +00:00
* L * ipc * asdfghjkl * dfghjk * it works! * types * patches for next.js * sdfghj * wsdfgn,./ * this * yolo * okay loser * asdfghjk * add some more APIs * MESS * sdfghjkl * remove native events from streams * stuff * remove lazy(primordials) test * debugging * okay * less fake extensions object * fix `Buffer.toString()` args logic * fix deserialize * make tests work * add test for `Buffer.toString` args * Update server.zig * remove test * update test * Update spawn-streaming-stdin.test.ts * fix linux build * Update fs.test.ts * cli message improvements * dfshaj * Fix fs.watch bug maybe? * remove --------- Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { it, test, expect } from "bun:test";
|
|
import { spawn } from "bun";
|
|
import { bunExe, bunEnv, gcTick } from "harness";
|
|
import { closeSync, openSync } from "fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "path";
|
|
import { unlinkSync } from "node: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++) {
|
|
const tmperr = join(tmpdir(), "stdin-repro-error.log." + i);
|
|
var exited;
|
|
await (async function () {
|
|
const proc = spawn({
|
|
cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"],
|
|
stdout: "pipe",
|
|
stdin: "pipe",
|
|
stderr: Bun.file(tmperr),
|
|
env: bunEnv,
|
|
});
|
|
exited = proc.exited;
|
|
var counter = 0;
|
|
var inCounter = 0;
|
|
var chunks: any[] = [];
|
|
const prom = (async function () {
|
|
try {
|
|
for await (var chunk of proc.stdout) {
|
|
chunks.push(chunk);
|
|
}
|
|
} catch (e: any) {
|
|
console.log(e.stack);
|
|
throw e;
|
|
}
|
|
})();
|
|
|
|
const prom2 = (async function () {
|
|
while (true) {
|
|
proc.stdin!.write("Wrote to stdin!\n");
|
|
inCounter++;
|
|
await new Promise(resolve => setTimeout(resolve, 8));
|
|
|
|
if (inCounter === 4) break;
|
|
}
|
|
proc.stdin!.end();
|
|
})();
|
|
|
|
await Promise.all([prom, prom2]);
|
|
expect(Buffer.concat(chunks).toString().trim()).toBe("Wrote to stdin!\n".repeat(4).trim());
|
|
await proc.exited;
|
|
|
|
try {
|
|
unlinkSync(tmperr);
|
|
} catch (e) {}
|
|
})();
|
|
}
|
|
|
|
closeSync(maxFD);
|
|
const newMaxFD = openSync("/dev/null", "w");
|
|
closeSync(newMaxFD);
|
|
|
|
// assert we didn't leak any file descriptors
|
|
expect(newMaxFD).toBe(maxFD);
|
|
}, 20_000);
|