Parallelize this test

This commit is contained in:
Jarred Sumner
2024-03-07 02:28:06 -08:00
parent 4235e2f058
commit d2968eeb80

View File

@@ -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);