mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 09:03:37 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7bc4475b02
commit
c659bf81a7
1 file changed
+13
-3
@@ -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}` };
|
||||
|
||||
Reference in new issue
Block a user