Skip to content

Commit 050b8ba

Browse files
committed
test: deflake test-bench-errors
The 10ms timeout can expire before the benchmark callback starts. There is then no unsettled work to abort the rest of the run. Abort from inside the callback to guarantee pending work. Cover timeout errors separately with a zero timeout. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex
1 parent 97af3d7 commit 050b8ba

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎test/parallel/test-bench-errors.js‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ bench('aborted', { samples: 1, signal }, () => {});
4949

5050
bench('duplicate', { samples: 1, params: { value: 1 } }, completeSample);
5151
bench('duplicate', { samples: 1, params: { value: 1 } }, completeSample);
52+
bench('timeout', { samples: 1, timeout: 0 }, common.mustNotCall());
5253
bench('continues', options, completeSample);
53-
bench('timeout', { samples: 1, timeout: 10 }, async () => {
54+
55+
// Aborting from the callback guarantees that there is unsettled work.
56+
const controller = new AbortController();
57+
bench('unsettled abort', { samples: 1, signal: controller.signal }, common.mustCall(async () => {
58+
controller.abort(new Error('stop unsettled work'));
5459
await new Promise(() => {});
55-
});
56-
const suiteCompletion = suite('after unsettled timeout suite', () => {
57-
bench('after unsettled timeout', options, common.mustNotCall());
58-
bench.skip('skipped after unsettled timeout', options, common.mustNotCall());
60+
}));
61+
const suiteCompletion = suite('after unsettled abort suite', () => {
62+
bench('after unsettled abort', options, common.mustNotCall());
63+
bench.skip('skipped after unsettled abort', options, common.mustNotCall());
5964
});
6065
suiteCompletion.then(common.mustCall());
6166

@@ -67,13 +72,13 @@ stream.on('bench:complete', (result) => completions.push(result));
6772
stream.on('bench:sample', (sample) => sampleNames.push(sample.name));
6873
stream.on('bench:summary', (result) => { summary = result; });
6974
stream.on('end', common.mustCall(() => {
70-
assert.strictEqual(completions.length, 16);
75+
assert.strictEqual(completions.length, 17);
7176
assert.deepStrictEqual(summary.counts, {
7277
__proto__: null,
7378
completed: 3,
74-
failed: 12,
79+
failed: 13,
7580
skipped: 1,
76-
total: 16,
81+
total: 17,
7782
});
7883
assert.strictEqual(summary.success, false);
7984

@@ -109,11 +114,14 @@ stream.on('end', common.mustCall(() => {
109114
assert.strictEqual(duplicates[0].error, undefined);
110115
assert.match(duplicates[1].error.message, /duplicate benchmark identity/);
111116
assert.strictEqual(byName.get('continues')[0].error, undefined);
112-
const unsettled = byName.get('after unsettled timeout')[0].error;
117+
const aborted = byName.get('unsettled abort')[0].error;
118+
assert.strictEqual(aborted.code, 'ABORT_ERR');
119+
assert.deepStrictEqual(aborted.cause, controller.signal.reason);
120+
const unsettled = byName.get('after unsettled abort')[0].error;
113121
assert.strictEqual(unsettled.code, 'ABORT_ERR');
114-
assert.strictEqual(unsettled.cause.code, 'ERR_OPERATION_FAILED');
122+
assert.deepStrictEqual(unsettled.cause, aborted);
115123
assert.strictEqual(
116-
byName.get('skipped after unsettled timeout')[0].skip, true);
124+
byName.get('skipped after unsettled abort')[0].skip, true);
117125
setTimeout(40).then(common.mustCall(() => {
118126
assert.strictEqual(sampleNames.includes('late timeout'), false);
119127
}));

0 commit comments

Comments
 (0)