processTreeTerminator.test.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. import {
  2. spawn,
  3. spawnSync,
  4. type ChildProcessWithoutNullStreams,
  5. } from "node:child_process";
  6. import { mkdtemp, readFile, rm } from "node:fs/promises";
  7. import { tmpdir } from "node:os";
  8. import { join } from "node:path";
  9. import { setTimeout as delay } from "node:timers/promises";
  10. import { afterEach, describe, expect, it } from "vitest";
  11. import {
  12. captureProcessTreeSnapshot,
  13. shouldSpawnInDetachedProcessGroup,
  14. terminateProcessTree,
  15. terminateProcessTreeAndWait,
  16. type ProcessIdentity,
  17. type ProcessTreeSnapshot,
  18. } from "@zcode/services/process/processTreeTerminator";
  19. const activeChildren = new Set<ChildProcessWithoutNullStreams>();
  20. const tempDirs = new Set<string>();
  21. function isPidAlive(pid: number): boolean {
  22. try {
  23. process.kill(pid, 0);
  24. return true;
  25. } catch {
  26. return false;
  27. }
  28. }
  29. function isPidRunning(pid: number): boolean {
  30. if (!isPidAlive(pid)) {
  31. return false;
  32. }
  33. if (process.platform === "win32") {
  34. return true;
  35. }
  36. const result = spawnSync("ps", ["-o", "stat=", "-p", String(pid)], {
  37. encoding: "utf8",
  38. });
  39. const status = result.stdout.trim();
  40. return status.length > 0 && !status.startsWith("Z");
  41. }
  42. async function waitForPidExit(
  43. pid: number,
  44. timeoutMs = 4_000,
  45. ): Promise<boolean> {
  46. const deadline = Date.now() + timeoutMs;
  47. while (Date.now() < deadline) {
  48. if (!isPidAlive(pid)) {
  49. return true;
  50. }
  51. await delay(50);
  52. }
  53. return !isPidAlive(pid);
  54. }
  55. async function waitForProcessTreeSnapshotIdentity(
  56. child: ChildProcessWithoutNullStreams,
  57. pid: number,
  58. timeoutMs = 4_000,
  59. ): Promise<
  60. | {
  61. snapshot: ProcessTreeSnapshot;
  62. identity: ProcessIdentity;
  63. }
  64. | undefined
  65. > {
  66. const deadline = Date.now() + timeoutMs;
  67. while (Date.now() < deadline) {
  68. const snapshot = captureProcessTreeSnapshot(child);
  69. const identity = snapshot?.identities.find((item) => item.pid === pid);
  70. if (snapshot && identity) {
  71. return { snapshot, identity };
  72. }
  73. await delay(50);
  74. }
  75. const snapshot = captureProcessTreeSnapshot(child);
  76. const identity = snapshot?.identities.find((item) => item.pid === pid);
  77. return snapshot && identity ? { snapshot, identity } : undefined;
  78. }
  79. function readFirstStdoutLine(child: ChildProcessWithoutNullStreams): Promise<string> {
  80. return new Promise((resolve, reject) => {
  81. let buffer = "";
  82. let stderrBuffer = "";
  83. // 修复原因:嵌套 Node 启动可能超过 2 秒,但此时尚未开始验证回收。
  84. // 就绪由完整输出行确认,挂起由测试整体超时约束,不另设启动竞速窗口。
  85. const cleanup = () => {
  86. child.stdout.off("data", onStdout);
  87. child.stderr.off("data", onStderr);
  88. child.off("error", onError);
  89. child.off("close", onClose);
  90. };
  91. const onStdout = (chunk: Buffer) => {
  92. buffer += chunk.toString("utf8");
  93. const newlineIndex = buffer.indexOf("\n");
  94. if (newlineIndex < 0) {
  95. return;
  96. }
  97. cleanup();
  98. resolve(buffer.slice(0, newlineIndex).trim());
  99. };
  100. const onStderr = (chunk: Buffer) => {
  101. stderrBuffer += chunk.toString("utf8");
  102. };
  103. const onError = (error: Error) => {
  104. cleanup();
  105. reject(error);
  106. };
  107. const onClose = (code: number | null, signal: NodeJS.Signals | null) => {
  108. cleanup();
  109. reject(
  110. new Error(
  111. `child exited before reporting pid code=${code} signal=${signal} stdout=${JSON.stringify(buffer)} stderr=${JSON.stringify(stderrBuffer)}`,
  112. ),
  113. );
  114. };
  115. child.stdout.on("data", onStdout);
  116. child.stderr.on("data", onStderr);
  117. child.once("error", onError);
  118. child.once("close", onClose);
  119. });
  120. }
  121. async function readReportedPid(
  122. child: ChildProcessWithoutNullStreams,
  123. pidFilePath?: string,
  124. ): Promise<number> {
  125. let stdoutLine = "";
  126. try {
  127. stdoutLine = await readFirstStdoutLine(child);
  128. const stdoutPid = Number(stdoutLine);
  129. if (Number.isInteger(stdoutPid)) {
  130. return stdoutPid;
  131. }
  132. } catch (error) {
  133. if (!pidFilePath) {
  134. throw error;
  135. }
  136. }
  137. if (pidFilePath) {
  138. const filePid = Number((await readFile(pidFilePath, "utf8")).trim());
  139. if (Number.isInteger(filePid)) {
  140. return filePid;
  141. }
  142. }
  143. throw new Error(`child reported invalid pid: ${JSON.stringify(stdoutLine)}`);
  144. }
  145. afterEach(async () => {
  146. for (const child of activeChildren) {
  147. if (child.pid && process.platform !== "win32") {
  148. try {
  149. process.kill(-child.pid, "SIGKILL");
  150. } catch {
  151. /* 测试兜底清理,进程已退出时忽略。 */
  152. }
  153. }
  154. terminateProcessTree(child);
  155. }
  156. activeChildren.clear();
  157. for (const dir of tempDirs) {
  158. await rm(dir, { recursive: true, force: true });
  159. }
  160. tempDirs.clear();
  161. });
  162. describe("terminateProcessTree", () => {
  163. it("回收 runtime wrapper 时会一并结束其派生子进程", async () => {
  164. const dir = await mkdtemp(join(tmpdir(), "zcode-runtime-terminator-"));
  165. tempDirs.add(dir);
  166. const grandchildPidPath = join(dir, "grandchild.pid");
  167. const child = spawn(
  168. process.execPath,
  169. [
  170. "-e",
  171. `
  172. const { writeFileSync } = require("node:fs");
  173. const { spawn } = require("node:child_process");
  174. const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
  175. stdio: "ignore",
  176. });
  177. writeFileSync(${JSON.stringify(grandchildPidPath)}, String(child.pid));
  178. process.stdout.write(String(child.pid) + "\\n");
  179. setInterval(() => {}, 1000);
  180. `,
  181. ],
  182. {
  183. detached: shouldSpawnInDetachedProcessGroup(),
  184. stdio: ["ignore", "pipe", "pipe"],
  185. windowsHide: true,
  186. },
  187. );
  188. activeChildren.add(child);
  189. const grandchildPid = await readReportedPid(child, grandchildPidPath);
  190. expect(isPidAlive(grandchildPid)).toBe(true);
  191. // Bugfix: 用户反馈退出 ZCode 后仍残留 bun 版本的 Agent 子进程。
  192. // 这里用 wrapper -> grandchild 的结构复现,要求关闭 wrapper 时整棵进程树都被回收。
  193. terminateProcessTree(child);
  194. expect(await waitForPidExit(child.pid!)).toBe(true);
  195. expect(await waitForPidExit(grandchildPid)).toBe(true);
  196. activeChildren.delete(child);
  197. });
  198. // Bugfix: Windows 的 taskkill 进程树回收不会向 Node 子进程交付 POSIX SIGTERM。
  199. // 该用例只验证 POSIX graceful shutdown 窗口,Windows 另由进程树清理用例覆盖。
  200. it.runIf(process.platform !== "win32")(
  201. "关闭 runtime wrapper 时先给进程处理 SIGTERM 的窗口",
  202. async () => {
  203. const dir = await mkdtemp(join(tmpdir(), "zcode-runtime-terminator-"));
  204. tempDirs.add(dir);
  205. const markerPath = join(dir, "graceful-exit.txt");
  206. const child = spawn(
  207. process.execPath,
  208. [
  209. "-e",
  210. `
  211. const { writeFileSync } = require("node:fs");
  212. process.on("SIGTERM", () => {
  213. writeFileSync(${JSON.stringify(markerPath)}, "sigterm");
  214. setTimeout(() => process.exit(0), 150);
  215. });
  216. console.log("ready");
  217. setInterval(() => {}, 1000);
  218. `,
  219. ],
  220. {
  221. detached: shouldSpawnInDetachedProcessGroup(),
  222. stdio: ["ignore", "pipe", "pipe"],
  223. windowsHide: true,
  224. },
  225. );
  226. activeChildren.add(child);
  227. await readFirstStdoutLine(child);
  228. // Bugfix: 回收残留进程不能把正常关闭路径变成立即 SIGKILL;
  229. // runtime 仍需要一点时间 flush 会话状态、关闭 MCP 连接和清理临时资源。
  230. terminateProcessTree(child);
  231. await delay(50);
  232. expect(isPidAlive(child.pid!)).toBe(true);
  233. expect(await readFile(markerPath, "utf8")).toBe("sigterm");
  234. expect(await waitForPidExit(child.pid!)).toBe(true);
  235. activeChildren.delete(child);
  236. },
  237. );
  238. it.runIf(process.platform !== "win32")(
  239. "POSIX 下会兜底清理脱离原进程组的后代进程",
  240. async () => {
  241. const dir = await mkdtemp(join(tmpdir(), "zcode-runtime-terminator-"));
  242. tempDirs.add(dir);
  243. const grandchildPidPath = join(dir, "detached-grandchild.pid");
  244. const child = spawn(
  245. process.execPath,
  246. [
  247. "-e",
  248. `
  249. const { writeFileSync } = require("node:fs");
  250. const { spawn } = require("node:child_process");
  251. const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
  252. detached: true,
  253. stdio: "ignore",
  254. });
  255. child.unref();
  256. writeFileSync(${JSON.stringify(grandchildPidPath)}, String(child.pid));
  257. process.stdout.write(String(child.pid) + "\\n");
  258. setInterval(() => {}, 1000);
  259. `,
  260. ],
  261. {
  262. detached: shouldSpawnInDetachedProcessGroup(),
  263. stdio: ["ignore", "pipe", "pipe"],
  264. windowsHide: true,
  265. },
  266. );
  267. activeChildren.add(child);
  268. const grandchildPid = await readReportedPid(child, grandchildPidPath);
  269. expect(isPidAlive(grandchildPid)).toBe(true);
  270. // Bugfix: 有些 runtime 或插件会把后代进程 detached 到自己的进程组;
  271. // 只 kill runtime wrapper 的进程组会留下这类后代进程,必须按已发现的进程树兜底清理。
  272. terminateProcessTree(child);
  273. expect(await waitForPidExit(child.pid!)).toBe(true);
  274. expect(await waitForPidExit(grandchildPid)).toBe(true);
  275. activeChildren.delete(child);
  276. },
  277. );
  278. it.runIf(process.platform !== "win32")(
  279. "非等待式回收会强制结束忽略 SIGTERM 的 runtime 进程树",
  280. async () => {
  281. const child = spawn(
  282. process.execPath,
  283. [
  284. "-e",
  285. `
  286. const { spawn } = require("node:child_process");
  287. const descendant = spawn(
  288. process.execPath,
  289. ["-e", 'process.on("SIGTERM", () => {}); process.send?.("ready"); setInterval(() => {}, 1000);'],
  290. { detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"] },
  291. );
  292. process.on("SIGTERM", () => {});
  293. descendant.once("message", () => process.stdout.write(String(descendant.pid) + "\\n"));
  294. setInterval(() => {}, 1000);
  295. `,
  296. ],
  297. {
  298. detached: shouldSpawnInDetachedProcessGroup(),
  299. stdio: ["ignore", "pipe", "pipe"],
  300. windowsHide: true,
  301. },
  302. );
  303. activeChildren.add(child);
  304. const descendantPid = await readReportedPid(child);
  305. try {
  306. // 修复原因:公开的非等待式关闭不会注入 force 观察回调;强杀副作用不能
  307. // 依赖该可选回调,否则忽略 SIGTERM 的 runtime 与 detached MCP 会永久残留。
  308. terminateProcessTree(child, { forceAfterMs: 20 });
  309. expect(await waitForPidExit(child.pid!)).toBe(true);
  310. expect(await waitForPidExit(descendantPid)).toBe(true);
  311. } finally {
  312. for (const pid of [child.pid, descendantPid]) {
  313. if (pid && isPidRunning(pid)) {
  314. try {
  315. process.kill(-pid, "SIGKILL");
  316. } catch {
  317. /* 测试兜底清理,进程已退出时忽略。 */
  318. }
  319. }
  320. }
  321. }
  322. activeChildren.delete(child);
  323. },
  324. );
  325. it.runIf(process.platform !== "win32")(
  326. "查询 root 身份失败时记录 warn 且延迟 force 不沿裸 PID 重新发现",
  327. async () => {
  328. const child = spawn(
  329. process.execPath,
  330. ["-e", "setInterval(() => {}, 1000)"],
  331. {
  332. detached: shouldSpawnInDetachedProcessGroup(),
  333. stdio: ["ignore", "pipe", "pipe"],
  334. windowsHide: true,
  335. },
  336. );
  337. activeChildren.add(child);
  338. await delay(50);
  339. const warnMessages: string[] = [];
  340. const originalPath = process.env.PATH;
  341. process.env.PATH = "";
  342. try {
  343. terminateProcessTree(child, {
  344. forceAfterMs: 20,
  345. log: {
  346. warn: (_traceId, ...args) => {
  347. warnMessages.push(args.map(String).join(" "));
  348. },
  349. },
  350. });
  351. } finally {
  352. if (originalPath === undefined) {
  353. delete process.env.PATH;
  354. } else {
  355. process.env.PATH = originalPath;
  356. }
  357. }
  358. expect(
  359. warnMessages.some((message) =>
  360. message.includes("查询 runtime 后代进程失败"),
  361. ),
  362. ).toBe(true);
  363. // 修复原因:首次查询失败后即使 PATH 已恢复,force timer 也不能沿裸 PID
  364. // 重新认领进程树;ChildProcess.kill 同样只是 PID 信号,不是稳定 OS 句柄。
  365. await delay(100);
  366. expect(isPidAlive(child.pid!)).toBe(true);
  367. },
  368. );
  369. it.runIf(process.platform !== "win32")(
  370. "等待式回收会撑到 SIGKILL 兜底完成",
  371. async () => {
  372. const child = spawn(
  373. process.execPath,
  374. [
  375. "-e",
  376. `
  377. process.on("SIGTERM", () => {});
  378. console.log("ready");
  379. setInterval(() => {}, 1000);
  380. `,
  381. ],
  382. {
  383. detached: shouldSpawnInDetachedProcessGroup(),
  384. stdio: ["ignore", "pipe", "pipe"],
  385. windowsHide: true,
  386. },
  387. );
  388. activeChildren.add(child);
  389. await readFirstStdoutLine(child);
  390. // Bugfix: app 关闭时 host 不能只安排一个 unref 的 SIGKILL 兜底就退出;
  391. // 遇到忽略 SIGTERM 的 zcode-cli/app-server 时,必须等兜底执行完再让 host 结束。
  392. const result = await terminateProcessTreeAndWait(child, {
  393. forceAfterMs: 20,
  394. waitAfterForceMs: 20,
  395. });
  396. expect(result).toEqual({ remainingPids: [] });
  397. expect(await waitForPidExit(child.pid!, 1_000)).toBe(true);
  398. activeChildren.delete(child);
  399. },
  400. );
  401. it.runIf(process.platform !== "win32")(
  402. "根进程先退出时仍等待 detached 后代完成强制回收",
  403. async () => {
  404. const child = spawn(
  405. process.execPath,
  406. [
  407. "-e",
  408. `
  409. const { spawn } = require("node:child_process");
  410. const descendant = spawn(
  411. process.execPath,
  412. ["-e", 'process.on("SIGTERM", () => {}); process.send?.("ready"); setInterval(() => {}, 1000);'],
  413. { detached: true, stdio: ["ignore", "ignore", "ignore", "ipc"] },
  414. );
  415. descendant.once("message", () => process.stdout.write(String(descendant.pid) + "\\n"));
  416. setInterval(() => {}, 1000);
  417. `,
  418. ],
  419. {
  420. detached: shouldSpawnInDetachedProcessGroup(),
  421. stdio: ["ignore", "pipe", "pipe"],
  422. windowsHide: true,
  423. },
  424. );
  425. activeChildren.add(child);
  426. const descendantPid = await readReportedPid(child);
  427. expect(isPidAlive(descendantPid)).toBe(true);
  428. try {
  429. // 修复原因:runtime 根进程收到 SIGTERM 后可能先于 detached MCP
  430. // 退出。等待边界必须是整棵已发现进程树,不能只观察根 child。
  431. await terminateProcessTreeAndWait(child, {
  432. forceAfterMs: 30,
  433. waitAfterForceMs: 30,
  434. });
  435. expect(isPidRunning(descendantPid)).toBe(false);
  436. } finally {
  437. if (isPidAlive(descendantPid)) {
  438. try {
  439. process.kill(-descendantPid, "SIGKILL");
  440. } catch {
  441. /* 测试兜底清理,进程已退出时忽略。 */
  442. }
  443. }
  444. }
  445. activeChildren.delete(child);
  446. },
  447. );
  448. it.runIf(process.platform !== "win32")(
  449. "延迟回收不会终止 PID 相同但创建标识已变化的进程",
  450. async () => {
  451. const child = spawn(
  452. process.execPath,
  453. [
  454. "-e",
  455. `
  456. const { spawn } = require("node:child_process");
  457. const descendant = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], {
  458. detached: true,
  459. stdio: "ignore",
  460. });
  461. descendant.unref();
  462. process.on("message", (message) => {
  463. if (message === "exit") process.exit(0);
  464. });
  465. process.stdout.write(String(descendant.pid) + "\\n");
  466. `,
  467. ],
  468. {
  469. detached: shouldSpawnInDetachedProcessGroup(),
  470. stdio: ["ignore", "pipe", "pipe", "ipc"],
  471. windowsHide: true,
  472. },
  473. );
  474. activeChildren.add(child);
  475. const descendantPid = await readReportedPid(child);
  476. // 修复原因:stdout 已写出 PID 不代表 ps 的父子/进程组视图已经稳定;
  477. // 由父测试控制 wrapper 退出,并等待包含创建标识的快照,避免固定等待竞态。
  478. const captured = await waitForProcessTreeSnapshotIdentity(child, descendantPid);
  479. expect(captured).toBeDefined();
  480. const { snapshot, identity: descendantIdentity } = captured!;
  481. child.send("exit");
  482. expect(await waitForPidExit(child.pid!)).toBe(true);
  483. try {
  484. // 修复原因:延迟强杀时裸 PID 可能已被系统复用。用错误创建标识模拟
  485. // 同 PID 的新进程,回收器必须把原成员视为已退出,不能向当前进程发信号。
  486. await terminateProcessTreeAndWait(child, {
  487. forceAfterMs: 20,
  488. waitAfterForceMs: 20,
  489. snapshot: {
  490. ...snapshot,
  491. identities: snapshot.identities.map((identity) =>
  492. identity.pid === descendantIdentity.pid
  493. ? { ...identity, startTime: `${descendantIdentity.startTime}-reused` }
  494. : identity,
  495. ),
  496. },
  497. });
  498. expect(isPidRunning(descendantPid)).toBe(true);
  499. } finally {
  500. if (isPidRunning(descendantPid)) {
  501. process.kill(-descendantPid, "SIGKILL");
  502. }
  503. }
  504. activeChildren.delete(child);
  505. },
  506. );
  507. it.runIf(process.platform !== "win32")("根进程已退出时仍按原进程组回收同组后代", async () => {
  508. const child = spawn(
  509. process.execPath,
  510. [
  511. "-e",
  512. `
  513. const { spawn } = require("node:child_process");
  514. const descendant = spawn(
  515. process.execPath,
  516. ["-e", 'process.on("SIGTERM", () => {}); process.send?.("ready"); setInterval(() => {}, 1000);'],
  517. { stdio: ["ignore", "ignore", "ignore", "ipc"] },
  518. );
  519. descendant.once("message", () => {
  520. process.stdout.write(String(descendant.pid) + "\\n");
  521. });
  522. process.on("message", (message) => {
  523. if (message === "exit") process.exit(0);
  524. });
  525. `,
  526. ],
  527. {
  528. detached: shouldSpawnInDetachedProcessGroup(),
  529. stdio: ["ignore", "pipe", "pipe", "ipc"],
  530. windowsHide: true,
  531. },
  532. );
  533. activeChildren.add(child);
  534. const descendantPid = await readReportedPid(child);
  535. // 修复原因:固定 100ms 后退出会与父测试取快照竞争;确认身份后再允许根进程退出。
  536. const captured = await waitForProcessTreeSnapshotIdentity(child, descendantPid);
  537. expect(captured).toBeDefined();
  538. const { snapshot } = captured!;
  539. child.send("exit");
  540. expect(await waitForPidExit(child.pid!)).toBe(true);
  541. expect(isPidRunning(descendantPid)).toBe(true);
  542. try {
  543. // 修复原因:CLI 根进程异常退出后,同组 MCP 仍可能存活;必须用根进程
  544. // 生前快照证明该 PGID 内仍有原成员,不能只凭已退出的裸 root PID 发信号。
  545. await terminateProcessTreeAndWait(child, {
  546. forceAfterMs: 30,
  547. waitAfterForceMs: 30,
  548. snapshot,
  549. });
  550. expect(isPidRunning(descendantPid)).toBe(false);
  551. } finally {
  552. if (isPidRunning(descendantPid)) {
  553. process.kill(-child.pid!, "SIGKILL");
  554. }
  555. }
  556. activeChildren.delete(child);
  557. });
  558. it.runIf(process.platform !== "win32")(
  559. "健康 runtime 提前退出时不会固定等待兜底窗口",
  560. async () => {
  561. const child = spawn(
  562. process.execPath,
  563. ["-e", "setInterval(() => {}, 1000)"],
  564. {
  565. detached: shouldSpawnInDetachedProcessGroup(),
  566. stdio: ["ignore", "pipe", "pipe"],
  567. windowsHide: true,
  568. },
  569. );
  570. activeChildren.add(child);
  571. await delay(50);
  572. const startedAt = Date.now();
  573. const waitPromise = terminateProcessTreeAndWait(child, {
  574. forceAfterMs: 1_500,
  575. waitAfterForceMs: 100,
  576. });
  577. setTimeout(() => {
  578. child.kill();
  579. }, 100).unref?.();
  580. // Bugfix: 旧等待式回收固定 sleep graceful + force 窗口;
  581. // 健康 runtime 在 SIGTERM 后提前退出时,不应继续卡满 2.25 秒。
  582. await waitPromise;
  583. const durationMs = Date.now() - startedAt;
  584. expect(await waitForPidExit(child.pid!, 1_000)).toBe(true);
  585. expect(durationMs).toBeLessThan(1_200);
  586. activeChildren.delete(child);
  587. },
  588. );
  589. });