Skip to content

Commit 415fcde

Browse files
TrottBridgeAR
authored andcommitted
test: fix flaky VM timeout test on Raspberry Pi
Increase the timeouts based on platform. This required adjusting common.platformTimeout() to deal with bigint. Fixes: #24120 PR-URL: #24238 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent f669817 commit 415fcde

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

test/common/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,12 @@ See `common.expectWarning()` for usage.
271271
Indicates whether 'opensslCli' is supported.
272272

273273
### platformTimeout(ms)
274-
* `ms` [&lt;number>]
275-
* return [&lt;number>]
274+
* `ms` [&lt;number>|&lt;bigint>]
275+
* return [&lt;number>|&lt;bigint>]
276276

277-
Platform normalizes timeout.
277+
Returns a timeout value based on detected conditions. For example, a debug build
278+
may need extra time so the returned value will be larger than on a release
279+
build.
278280

279281
### PIPE
280282
* [&lt;string>]

test/common/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,31 @@ const pwdCommand = isWindows ?
187187

188188

189189
function platformTimeout(ms) {
190+
// ESLint will not support 'bigint' in valid-typeof until it reaches stage 4.
191+
// See https://github.com/eslint/eslint/pull/9636.
192+
// eslint-disable-next-line valid-typeof
193+
const multipliers = typeof ms === 'bigint' ?
194+
{ two: 2n, four: 4n, seven: 7n } : { two: 2, four: 4, seven: 7 };
195+
190196
if (process.features.debug)
191-
ms = 2 * ms;
197+
ms = multipliers.two * ms;
192198

193199
if (global.__coverage__)
194-
ms = 4 * ms;
200+
ms = multipliers.four * ms;
195201

196202
if (isAIX)
197-
return 2 * ms; // default localhost speed is slower on AIX
203+
return multipliers.two * ms; // default localhost speed is slower on AIX
198204

199205
if (process.arch !== 'arm')
200206
return ms;
201207

202208
const armv = process.config.variables.arm_version;
203209

204210
if (armv === '6')
205-
return 7 * ms; // ARMv6
211+
return multipliers.seven * ms; // ARMv6
206212

207213
if (armv === '7')
208-
return 2 * ms; // ARMv7
214+
return multipliers.two * ms; // ARMv7
209215

210216
return ms; // ARMv8+
211217
}

test/known_issues/known_issues.status

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ prefix known_issues
99
[$system==win32]
1010

1111
[$system==linux]
12-
test-vm-timeout-escape-nexttick: PASS,FLAKY
1312
test-vm-timeout-escape-promise: PASS,FLAKY
1413
test-vm-timeout-escape-queuemicrotask: PASS,FLAKY
1514

test/known_issues/test-vm-timeout-escape-nexttick.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Promises, nextTick, and queueMicrotask allow code to escape the timeout
55
// set for runInContext, runInNewContext, and runInThisContext
66

7-
require('../common');
7+
const common = require('../common');
88
const assert = require('assert');
99
const vm = require('vm');
1010

@@ -13,12 +13,14 @@ const NS_PER_MS = 1000000n;
1313
const hrtime = process.hrtime.bigint;
1414
const nextTick = process.nextTick;
1515

16+
const waitDuration = common.platformTimeout(100n);
17+
1618
function loop() {
1719
const start = hrtime();
1820
while (1) {
1921
const current = hrtime();
2022
const span = (current - start) / NS_PER_MS;
21-
if (span >= 100n) {
23+
if (span >= waitDuration) {
2224
throw new Error(
2325
`escaped timeout at ${span} milliseconds!`);
2426
}
@@ -33,9 +35,8 @@ assert.throws(() => {
3335
nextTick,
3436
loop
3537
},
36-
{ timeout: 5 }
38+
{ timeout: common.platformTimeout(5) }
3739
);
3840
}, {
39-
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT',
40-
message: 'Script execution timed out after 5ms'
41+
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT'
4142
});

0 commit comments

Comments
 (0)