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

4 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎test/common/README.md‎

Lines changed: 5 additions & 3 deletions
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‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,31 @@ const pwdCommand = isWindows ?
187187

188188

189189
functionplatformTimeout(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+
constmultipliers=typeofms==='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-
return2*ms;// default localhost speed is slower on AIX
203+
returnmultipliers.two*ms;// default localhost speed is slower on AIX
198204

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

202208
constarmv=process.config.variables.arm_version;
203209

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

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

210216
returnms;// ARMv8+
211217
}

‎test/known_issues/known_issues.status‎

Lines changed: 0 additions & 1 deletion
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‎

Lines changed: 6 additions & 5 deletions
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+
constcommon=require('../common');
88
constassert=require('assert');
99
constvm=require('vm');
1010

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

16+
constwaitDuration=common.platformTimeout(100n);
17+
1618
functionloop(){
1719
conststart=hrtime();
1820
while(1){
1921
constcurrent=hrtime();
2022
constspan=(current-start)/NS_PER_MS;
21-
if(span>=100n){
23+
if(span>=waitDuration){
2224
thrownewError(
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)