mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
Persist heartbeat child pid before stdin handoff
This commit is contained in:
parent
3baebee2df
commit
26d4cabb2e
2 changed files with 53 additions and 10 deletions
38
packages/adapter-utils/src/server-utils.test.ts
Normal file
38
packages/adapter-utils/src/server-utils.test.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { randomUUID } from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runChildProcess } from "./server-utils.js";
|
||||
|
||||
describe("runChildProcess", () => {
|
||||
it("waits for onSpawn before sending stdin to the child", async () => {
|
||||
const spawnDelayMs = 150;
|
||||
const startedAt = Date.now();
|
||||
let onSpawnCompletedAt = 0;
|
||||
|
||||
const result = await runChildProcess(
|
||||
randomUUID(),
|
||||
process.execPath,
|
||||
[
|
||||
"-e",
|
||||
"let data='';process.stdin.setEncoding('utf8');process.stdin.on('data',chunk=>data+=chunk);process.stdin.on('end',()=>process.stdout.write(data));",
|
||||
],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: {},
|
||||
stdin: "hello from stdin",
|
||||
timeoutSec: 5,
|
||||
graceSec: 1,
|
||||
onLog: async () => {},
|
||||
onSpawn: async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, spawnDelayMs));
|
||||
onSpawnCompletedAt = Date.now();
|
||||
},
|
||||
},
|
||||
);
|
||||
const finishedAt = Date.now();
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toBe("hello from stdin");
|
||||
expect(onSpawnCompletedAt).toBeGreaterThanOrEqual(startedAt + spawnDelayMs);
|
||||
expect(finishedAt - startedAt).toBeGreaterThanOrEqual(spawnDelayMs);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue