Files
node/test/parallel/test-bench-cli-ack.js
Filip Skokan f9defa61fa lib: fix benchmark record acknowledgement race
The child can receive an acknowledgement and send its next record before
the parent's send callback runs. Clear recordPending before sending the
acknowledgement to avoid rejecting that record as an invalid sequence.

Add a regression test that delays send callbacks until the child sends
its next record or closes.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66430
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-10-08 09:58:29 +00:00

24 lines
1022 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixtures = require('../common/fixtures');
const result = spawnSync(process.execPath, [
'--no-warnings', '--experimental-bench', '--bench',
'--require', fixtures.path('bench-runner/delayed-ack.cjs'),
'--bench-reporter=json',
fixtures.path('bench-runner/acknowledged-records.mjs'),
], { encoding: 'utf8', timeout: common.platformTimeout(30_000) });
assert.ifError(result.error);
assert.strictEqual(result.signal, null);
assert.strictEqual(result.status, 0, result.stdout + result.stderr);
assert.strictEqual(result.stderr, '');
const records = result.stdout.trim().split('\n').map((line) => JSON.parse(line));
const diagnostics = records.filter(({ type }) => type === 'bench:diagnostic');
assert.strictEqual(diagnostics.length, 32);
assert(diagnostics.every(({ data }) => /^acknowledged 10\d{3}$/.test(data.message)));
assert.strictEqual(records.at(-1).data.success, true);