MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / watched

Function watched

scripts/regression/gate.mjs:306–336  ·  view source on GitHub ↗

Run a harness on `cases`. What each finished case took, and the case it hung on, if it hung.

(script, size, extra, cases, read)

Source from the content-addressed store, hash-verified

304
305/** Run a harness on `cases`. What each finished case took, and the case it hung on, if it hung. */
306function watched(script, size, extra, cases, read) {
307 return new Promise((done, failed) => {
308 const child = spawn(node, [script, dist, size, ...extra], { env: { ...env, BENCH_CASES: cases.join(',') }, stdio: ['ignore', 'pipe', 'pipe'] });
309 const finished = new Map();
310 let out = '';
311 let err = '';
312 let hung = false;
313 let timer;
314 const wait = () => {
315 clearTimeout(timer);
316 timer = setTimeout(() => {
317 hung = true;
318 child.kill('SIGKILL');
319 }, CASE_LIMIT_SECONDS * 1000);
320 };
321 wait();
322 child.stdout.on('data', (chunk) => {
323 out += chunk;
324 for (const [name, took] of read(out)) if (!finished.has(name)) finished.set(name, took);
325 wait();
326 });
327 child.stderr.on('data', (chunk) => (err += chunk));
328 child.on('error', failed);
329 child.on('close', (code) => {
330 clearTimeout(timer);
331 if (hung) done({ finished, hung: cases.find((name) => !finished.has(name)) ?? null });
332 else if (code !== 0) failed(new Error(`${script} failed at ${size} MB:\n${err.slice(0, 2000)}`));
333 else done({ finished, hung: null });
334 });
335 });
336}
337
338/** Each generated case's seconds at each size, from the two benchmark harnesses. */
339async function growth() {

Callers 1

growthFunction · 0.85

Calls 9

spawnFunction · 0.85
waitFunction · 0.85
failedFunction · 0.85
hasMethod · 0.80
onMethod · 0.65
readFunction · 0.50
doneFunction · 0.50
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected