From 668c87296aa55285e41d3cebab9d034ab191289a Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 5 Mar 2026 16:40:22 +0900 Subject: [PATCH 1/3] fix: use monotonic clock for test timeout guard The microtask timeout guard in `withTimeout` used `Date.now` which is non-monotonic and subject to clock adjustments (NTP sync, container time sync, suspend/resume). This could cause tests to falsely time out when the wall clock jumps forward, even though real elapsed time was well within the configured timeout. Switch to `performance.now()` (monotonic) consistent with `run.ts` and Node's internal `setTimeout` timer, so the guard only triggers when actual elapsed time exceeds the timeout. Closes #8276 Co-Authored-By: Claude Opus 4.6 --- packages/runner/src/context.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/runner/src/context.ts b/packages/runner/src/context.ts index f793b03c6901..538c204d17fa 100644 --- a/packages/runner/src/context.ts +++ b/packages/runner/src/context.ts @@ -14,7 +14,9 @@ import { PendingError } from './errors' import { finishSendTasksUpdate } from './run' import { getRunner } from './suite' -const now = Date.now +const now = globalThis.performance + ? globalThis.performance.now.bind(globalThis.performance) + : Date.now export const collectorContext: RuntimeContext = { tasks: [], From cd37955f8b80ff21da4777edb7b21eed47be2a82 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 10 Mar 2026 19:18:56 +0900 Subject: [PATCH 2/3] test: make BROWSER_WS_ENDPOINT easier --- test/browser/README.md | 2 +- test/browser/settings.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/browser/README.md b/test/browser/README.md index e2896e9bfc0a..f4217a00fb50 100644 --- a/test/browser/README.md +++ b/test/browser/README.md @@ -26,5 +26,5 @@ Some test suites don't support running it remotely (`fixtures/inspect` and `fixt pnpm docker up -d # Run tests with BROWSER_WS_ENDPOINT -BROWSER_WS_ENDPOINT=ws://127.0.0.1:6677/ pnpm run test:playwright +BROWSER_WS_ENDPOINT=true pnpm run test:playwright ``` diff --git a/test/browser/settings.ts b/test/browser/settings.ts index fc6493cd5cca..c6bb019a38f9 100644 --- a/test/browser/settings.ts +++ b/test/browser/settings.ts @@ -5,12 +5,14 @@ import { webdriverio } from '@vitest/browser-webdriverio' const providerName = (process.env.PROVIDER || 'playwright') as 'playwright' | 'webdriverio' | 'preview' +const wsEndpoint = process.env.BROWSER_WS_ENDPOINT === 'true' ? 'ws://127.0.0.1:6677/' : process.env.BROWSER_WS_ENDPOINT + export const providers = { - playwright: (options?: Parameters[0]) => playwright(process.env.BROWSER_WS_ENDPOINT + playwright: (options?: Parameters[0]) => playwright(wsEndpoint ? { ...options, connectOptions: { - wsEndpoint: process.env.BROWSER_WS_ENDPOINT, + wsEndpoint, exposeNetwork: '', }, } From 583818fbcb7b64fbaa5ada29235d06752d49223d Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 10 Mar 2026 19:19:16 +0900 Subject: [PATCH 3/3] fix: fix processTimeoutOptions diff --- packages/browser/src/client/tester/tester-utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/browser/src/client/tester/tester-utils.ts b/packages/browser/src/client/tester/tester-utils.ts index c6e72485be33..a32a52fad9d9 100644 --- a/packages/browser/src/client/tester/tester-utils.ts +++ b/packages/browser/src/client/tester/tester-utils.ts @@ -186,7 +186,9 @@ export class CommandsManager { } } -const now = Date.now +const now = globalThis.performance + ? globalThis.performance.now.bind(globalThis.performance) + : Date.now export function processTimeoutOptions(options_: T | undefined): T | undefined { if ( @@ -212,7 +214,7 @@ export function processTimeoutOptions(options_: options_ = options_ || {} as T const currentTime = now() const endTime = startTime + timeout - const remainingTime = endTime - currentTime + const remainingTime = Math.floor(endTime - currentTime) if (remainingTime <= 0) { return options_ }