8376555099
- Observed timed-out child lifecycle failures without altering awaited rejection semantics. - Added coverage for callers that settle without observing the lifecycle promise. Fixes #6635
30 lines
1008 B
TypeScript
30 lines
1008 B
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { spawn, TimeoutError } from "@oh-my-pi/pi-utils/ptree";
|
|
|
|
describe("ptree timeout", () => {
|
|
it("contains the lifecycle rejection when the caller does not observe exited", async () => {
|
|
const unhandled = new Set<unknown>();
|
|
const onUnhandled = (reason: unknown) => {
|
|
unhandled.add(reason);
|
|
};
|
|
process.on("unhandledRejection", onUnhandled);
|
|
|
|
try {
|
|
// Bun's subprocess timeout uses the platform clock; fake timers cannot drive this lifecycle.
|
|
using child = spawn(["bun", "-e", "Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0)"], {
|
|
timeout: 20,
|
|
});
|
|
await child.nothrow().text();
|
|
await child.proc.exited;
|
|
const nextTurn = Promise.withResolvers<void>();
|
|
setImmediate(nextTurn.resolve);
|
|
await nextTurn.promise;
|
|
|
|
expect(child.exitReason).toBeInstanceOf(TimeoutError);
|
|
expect(unhandled.has(child.exitReason)).toBe(false);
|
|
} finally {
|
|
process.off("unhandledRejection", onUnhandled);
|
|
}
|
|
});
|
|
});
|