Skip to content

Commit 5ec4233

Browse files
test(fuzz): let the watchdog outlive vitest's default case timeout (#1414)
A wedged parser was surfacing as a bare 'Test timed out in 5000ms' instead of the named hang: failure that says which input wedged, because the file's vitest timeout was shorter than the watchdog budget times the number of replayed cases. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 97b61f2 commit 5ec4233

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎scripts/fuzz/corpus-replay.test.ts‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import { FUZZ_TARGETS } from './targets.ts';
2020
*/
2121
const CASE_TIMEOUT_MS = 5_000;
2222

23+
/**
24+
* Vitest must outlast the watchdog for every case a test replays, or a wedged parser is reported as
25+
* a bare `Test timed out` instead of the named `hang:` failure that says which input wedged.
26+
*/
27+
const timeoutFor = (cases: number) => cases * CASE_TIMEOUT_MS + 10_000;
28+
2329
describe('parser fuzz regression corpus', () => {
2430
const corpus = readCorpus();
2531

@@ -49,6 +55,7 @@ describe('parser fuzz regression corpus', () => {
4955
const failures = await runCases(target, cases, CASE_TIMEOUT_MS);
5056
expect(failures.map(describeFailure)).toEqual([]);
5157
},
58+
timeoutFor(corpus.length + Math.max(...FUZZ_TARGETS.map((t) => t.seeds.length))),
5259
);
5360
});
5461

@@ -61,10 +68,16 @@ describe('fuzz case generation', () => {
6168
expect(sample(7)).not.toEqual(sample(8));
6269
});
6370

64-
it('generates strings the target can be fed directly', async () => {
65-
const inputs = fc.sample(arbitraryForTarget(target), { numRuns: 64, seed: 1 });
66-
expect(inputs.every((input) => typeof input === 'string')).toBe(true);
67-
const failures = await runCases(target, inputs, CASE_TIMEOUT_MS);
68-
expect(failures.map(describeFailure)).toEqual([]);
69-
});
71+
const GENERATED_CASES = 64;
72+
73+
it(
74+
'generates strings the target can be fed directly',
75+
async () => {
76+
const inputs = fc.sample(arbitraryForTarget(target), { numRuns: GENERATED_CASES, seed: 1 });
77+
expect(inputs.every((input) => typeof input === 'string')).toBe(true);
78+
const failures = await runCases(target, inputs, CASE_TIMEOUT_MS);
79+
expect(failures.map(describeFailure)).toEqual([]);
80+
},
81+
timeoutFor(GENERATED_CASES),
82+
);
7083
});

0 commit comments

Comments
 (0)