Skip to content

Commit 2e1cccc

Browse files
authored
Merge pull request #5791 from cloudflare/yagiz/fix-flaky-windows
fix flaky tests in windows
2 parents 053d555 + a0422d8 commit 2e1cccc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/workerd/api/node/tests/timers-global-override-test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,23 @@ export const testClearIntervalAcceptsBothTypes = {
153153
};
154154

155155
// Test that the refresh() method works correctly
156+
// NOTE: Using larger timing margins (200ms/100ms instead of 50ms/30ms) because
157+
// Windows has ~15.6ms timer resolution and significant jitter under load.
156158
export const testTimeoutRefresh = {
157159
async test() {
158160
let callCount = 0;
159161

160-
// Create a timeout that would fire in 50ms
162+
// Create a timeout that would fire in 200ms
161163
const timeout = globalThis.setTimeout(() => {
162164
callCount++;
163-
}, 50);
165+
}, 200);
164166

165-
// Wait 30ms, then refresh (reset the timer)
166-
await new Promise((r) => globalThis.setTimeout(r, 30));
167+
// Wait 100ms, then refresh (reset the timer)
168+
await new Promise((r) => globalThis.setTimeout(r, 100));
167169
timeout.refresh();
168170

169-
// Wait another 30ms (total 60ms from start, but only 30ms from refresh)
170-
await new Promise((r) => globalThis.setTimeout(r, 30));
171+
// Wait another 100ms (total 200ms from start, but only 100ms from refresh)
172+
await new Promise((r) => globalThis.setTimeout(r, 100));
171173

172174
// The callback shouldn't have fired yet since we refreshed
173175
strictEqual(
@@ -176,8 +178,8 @@ export const testTimeoutRefresh = {
176178
'Callback should not have fired yet after refresh'
177179
);
178180

179-
// Wait another 30ms for the refreshed timer to fire
180-
await new Promise((r) => globalThis.setTimeout(r, 30));
181+
// Wait another 150ms for the refreshed timer to fire (with margin)
182+
await new Promise((r) => globalThis.setTimeout(r, 150));
181183

182184
// Now it should have fired
183185
strictEqual(callCount, 1, 'Callback should have fired once');

src/workerd/api/tests/jsrpc-timing-test-tail.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ export const test = {
118118
);
119119
}
120120

121-
// Return should happen at least 200ms after onset (handler sleeps for 500ms)
122-
if (timeToReturn < 200) {
121+
// Return should happen at least 50ms after onset (handler sleeps for 500ms)
122+
// NOTE: Using a lower threshold (50ms instead of 200ms) because Windows has
123+
// significant timer jitter and scheduler.wait() timing assumptions don't hold
124+
// reliably under load.
125+
if (timeToReturn < 50) {
123126
throw new Error(
124127
`Return event (${timeToReturn}ms) happened too quickly. ` +
125-
`Expected at least 200ms from onset (handler sleeps for 500ms before returning).`
128+
`Expected at least 50ms from onset (handler sleeps for 500ms before returning).`
126129
);
127130
}
128131

0 commit comments

Comments
 (0)