Skip to content

Commit 049413b

Browse files
B4nanclaude
andauthored
test: fix flaky requestHandlerTimeoutSecs test properly (#3343)
## Summary - Fixes the flaky `should respect the requestHandlerTimeoutSecs option` test in `browser_crawler.test.ts` - The previous fix (#3340) used `vitest.useFakeTimers({ shouldAdvanceTime: true })` which doesn't address the root cause - The actual issue is a race condition: if `crawler.run()` takes longer than ~1 second to complete cleanup after the 500ms timeout, the 1500ms "bad" timer fires before assertions run - This fix increases the "bad" timer delay from 1500ms to 60000ms so it can never fire during test execution, regardless of CPU load from parallel tests ## Test plan - [x] Ran `yarn test` 5 times - all passed (one run had a different unrelated test fail) - [x] The fix is simple and eliminates the race condition entirely 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e025934 commit 049413b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

test/core/crawlers/browser_crawler.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,23 @@ describe('BrowserCrawler', () => {
427427
await localStorageEmulator.init();
428428
const puppeteerPlugin = new PuppeteerPlugin(puppeteer);
429429

430-
vitest.useFakeTimers({ shouldAdvanceTime: true });
431430
try {
432431
const requestList = await RequestList.open({
433432
sources: [{ url: `${serverAddress}/?q=1` }],
434433
});
435434

436435
const callSpy = vitest.fn();
437436

437+
// Use a very long delay for "bad" so it can never fire during test execution.
438+
// The test verifies that the 500ms timeout aborts the handler before "bad" would fire.
438439
const browserCrawler = new BrowserCrawlerTest({
439440
browserPoolOptions: {
440441
browserPlugins: [puppeteerPlugin],
441442
},
442443
requestList,
443444
requestHandler: async () => {
444445
setTimeout(() => callSpy('good'), 300);
445-
setTimeout(() => callSpy('bad'), 1500);
446+
setTimeout(() => callSpy('bad'), 60_000);
446447
await new Promise(() => {});
447448
},
448449
requestHandlerTimeoutSecs: 0.5,
@@ -453,7 +454,6 @@ describe('BrowserCrawler', () => {
453454
expect(callSpy).toBeCalledTimes(1);
454455
expect(callSpy).toBeCalledWith('good');
455456
} finally {
456-
vitest.useRealTimers();
457457
await localStorageEmulator.destroy();
458458
}
459459
});

0 commit comments

Comments
 (0)