test(ci): 그룹 kill 시험이 손자가 생긴 뒤에 시한을 터뜨린다
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
`tests/system/ci-runner/provider-process-group.test.ts`
「kills and reaps a stubborn provider process group including its
descendant」가 runner run 309(#57, FE-GATE-013)에서
`ENOENT … descendant.pid`로 실패했다. #57이 바꾼 시험이 아니다.
원인: 시험이 `runProviderProcess`에 실제 250 ms 시한을 주고, 그 안에
provider node가 떠서 손자를 띄우고 pid 파일을 쓴다고 가정한다. 부하가
있는 runner에서 그 시작이 250 ms를 넘으면 그룹 kill이 pid 파일보다 먼저
와 확인할 손자가 없다(고정 시간 가정). 같은 시험이 손자가 사라졌는지를
provider close 직후 한 번만 본다. SIGKILL과 init의 회수는 close 뒤에
끝날 수 있어 같은 가정이다(이쪽은 실패가 관측되지 않았다).
고른 방법: 시험의 주제는 그룹 kill이지 provider가 얼마나 돌아도 되는지가
아니다. `runProviderProcess`의 주입 칸 `setTimer`로, 손자가 pid를 쓴 뒤에
시한을 터뜨린다. kill은 그대로 기본 `defaultKillProcessGroup`이 한다.
손자는 사라질 때까지 기다린다. pid 대기와 사라짐 대기는 둘 다 감시
5초를 둔다(시험이 매달리지 않게 하는 감시이지 provider 시한이 아니다).
pid가 끝내 안 생기면 감시 뒤 kill하고 pid 없음으로 실패한다. 제품 코드는
바꾸지 않는다.
버린 대안: 시한을 늘린다(시간 가정이 남고 시험이 그만큼 느려진다).
provider가 준비를 알리는 경로를 제품 코드에 더한다(시험만을 위한 공개
표면이 생긴다).
약해진 검사: 기본 타이머(`dependencies.setTimer ?? setTimeout`)로 시한이
끝나는 경로를 도는 시험이 이제 없다. 그 시험들은 모두 타이머를 주입한다.
기본값은 그 한 줄이고, 시한 뒤의 처리(그룹 kill, kill 실패 때 자식
fallback, close 뒤에 끝남)는 `tests/unit/security-provider-evidence.test.ts`의
`runProviderProcess` 시험 둘이 본다. 실제 그룹 kill과 손자 정리는 이
시험이 계속 본다.
검증(desktop, 시스템 컨테이너):
- RED 탐침: provider 시작을 400 ms 늦춘 사본에서 원래 시험이
`ENOENT … descendant.pid`로 실패했다(1/1). 고친 시험(pid 감시를 넣기 전
판)은 같은 사본에서 통과했다(435 ms). 탐침 사본은 커밋하지 않았다.
- 이 커밋의 트리(48d460e2)로 20/20 통과(desktop 부하 8.3~9.8, 12코어).
CPU 부하 프로세스는 얹지 않았다. runner가 같은 기계에서 다른 run을
돌고 있었다.
- 노트북: `check:types`, `lint`, `tests/unit/test-timeout-declarations.test.ts`
·`ungated-tests.test.ts` 통과.
Refs: 흔들림 기록 tests/system/ci-runner/provider-process-group.test.ts:11
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -21,22 +22,79 @@ describe("CI-runner provider process-group lifecycle", { timeout: childProcessTi
|
||||
"setInterval(() => {}, 1000);",
|
||||
].join("\n");
|
||||
|
||||
const running = runProviderProcess({
|
||||
executable: process.execPath,
|
||||
arguments: ["-e", source],
|
||||
environment: {
|
||||
PATH: process.env.PATH,
|
||||
DESCENDANT_PID_PATH: descendantPidPath,
|
||||
// 2026-11-13. A real 250 ms timer started the kill before a loaded runner
|
||||
// had started the descendant, so its pid file did not exist (ENOENT,
|
||||
// runner run 309). The subject is the group kill, not how long a
|
||||
// provider may run: the runner's timer fires once the descendant exists,
|
||||
// or after the watchdog, and then the missing pid fails the test.
|
||||
const startedAt = Date.now();
|
||||
const running = runProviderProcess(
|
||||
{
|
||||
executable: process.execPath,
|
||||
arguments: ["-e", source],
|
||||
environment: {
|
||||
PATH: process.env.PATH,
|
||||
DESCENDANT_PID_PATH: descendantPidPath,
|
||||
},
|
||||
timeoutMs: 250,
|
||||
},
|
||||
timeoutMs: 250,
|
||||
});
|
||||
{
|
||||
setTimer: (fire) => {
|
||||
const poll = setInterval(() => {
|
||||
const waiting = readPid(descendantPidPath) === undefined;
|
||||
if (waiting && Date.now() - startedAt <= PROCESS_WATCHDOG_MS) return;
|
||||
clearInterval(poll);
|
||||
fire();
|
||||
}, POLL_MS);
|
||||
return poll;
|
||||
},
|
||||
clearTimer: (timer) => clearInterval(timer),
|
||||
},
|
||||
);
|
||||
|
||||
await expect(running).rejects.toThrow(/timed out.*process close/u);
|
||||
const descendantPid = Number(await readFile(descendantPidPath, "utf8"));
|
||||
expect(Number.isSafeInteger(descendantPid) && descendantPid > 0).toBe(true);
|
||||
expect(() => process.kill(descendantPid, 0)).toThrow(/ESRCH|no such process/u);
|
||||
const descendantPid = readPid(descendantPidPath);
|
||||
expect(descendantPid).toBeDefined();
|
||||
await expect(waitForProcessGone(descendantPid!)).resolves.toBe(true);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const POLL_MS = 10;
|
||||
/**
|
||||
* Test watchdog only, not a provider deadline: how long the test waits for the
|
||||
* descendant to write its pid, and for it to be gone after the group kill.
|
||||
* SIGKILL and the reaper (the container's init, once the provider is gone)
|
||||
* finish after the provider's close event, so the descendant is polled until
|
||||
* it is gone instead of checked once.
|
||||
*/
|
||||
const PROCESS_WATCHDOG_MS = 5_000;
|
||||
|
||||
/** The pid the provider wrote, or undefined while the file is missing or partly written. */
|
||||
function readPid(file: string): number | undefined {
|
||||
let text: string;
|
||||
try {
|
||||
text = readFileSync(file, "utf8");
|
||||
} catch (error) {
|
||||
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return undefined;
|
||||
throw error;
|
||||
}
|
||||
const pid = Number(text);
|
||||
return /^[1-9][0-9]*$/u.test(text) && Number.isSafeInteger(pid) ? pid : undefined;
|
||||
}
|
||||
|
||||
async function waitForProcessGone(pid: number): Promise<boolean> {
|
||||
const deadline = Date.now() + PROCESS_WATCHDOG_MS;
|
||||
while (Date.now() <= deadline) {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
} catch (error) {
|
||||
if (error && typeof error === "object" && "code" in error && error.code === "ESRCH") return true;
|
||||
throw error;
|
||||
}
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, POLL_MS));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user