Run a harness on `cases`. What each finished case took, and the case it hung on, if it hung.
(script, size, extra, cases, read)
| 304 | |
| 305 | /** Run a harness on `cases`. What each finished case took, and the case it hung on, if it hung. */ |
| 306 | function 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. */ |
| 339 | async function growth() { |