From c659bf81a776bd474f22a49d271cba6b0f72675b Mon Sep 17 00:00:00 2001 From: Thomas Durieux <5577568+tdurieux@users.noreply.github.com> Date: Sun, 29 Nov 2026 07:54:00 +0000 Subject: [PATCH] test: detect structured streamer startup and stop children on timeout The streamer now logs {"event":"streamer_started"} instead of the text "streamer started", so readiness never resolved, every lifecycle test timed out, and the forked streamers were never killed. Their IPC channels kept mocha alive until GitHub cancelled the job after hours. Parse the JSON log lines for the event, and reject readiness before the mocha timeout so each test's finally block always stops its child. Co-Authored-By: Claude Opus 5.5 --- test/performance-streamer-integration.test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/performance-streamer-integration.test.js b/test/performance-streamer-integration.test.js index ccfc38b..2e1b762 100644 --- a/test/performance-streamer-integration.test.js +++ b/test/performance-streamer-integration.test.js @@ -6,7 +6,7 @@ const path = require("node:path"); const net = require("node:net"); const { randomBytes } = require("node:crypto"); const { once } = require("node:events"); -const { setTimeout } = require("node:timers"); +const { setTimeout, clearTimeout } = require("node:timers"); const { fetch } = globalThis; const mongoose = require("mongoose"); require("ts-node/register/transpile-only"); @@ -51,10 +51,20 @@ const uri = process.env.PERFORMANCE_MONGO_URI; }); const messages = []; child.on("message", message => messages.push(message)); const ready = new Promise((resolve, reject) => { + // Fail before the mocha timeout so callers' finally blocks always stop the child. + const deadline = setTimeout(() => reject(Error("Streamer did not report streamer_started")), 20000); + const settle = (fn, value) => { clearTimeout(deadline); fn(value); }; let logs = ""; - child.stdout.on("data", chunk => { logs += chunk; if (logs.includes("streamer started")) resolve(); }); + child.stdout.on("data", chunk => { + logs += chunk; const lines = logs.split("\n"); logs = lines.pop(); + for (const line of lines) { + let record; try { record = JSON.parse(line); } catch { continue; } + if (record.event === "streamer_started") settle(resolve); + } + }); child.stderr.on("data", () => {}); - child.once("error", reject); child.once("exit", code => reject(Error(`Streamer exited ${code} before serving`))); + child.once("error", error => settle(reject, error)); + child.once("exit", code => settle(reject, Error(`Streamer exited ${code} before serving`))); }); ready.catch(() => {}); return { child, ready, messages, directory, stale, url: `http://127.0.0.1:${port}` };