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: https://github.com/nodejs/node/issues/24120 PR-URL: https://github.com/nodejs/node/pull/24238 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
5c59622243
commit
d8e06b23b0
@ -271,10 +271,12 @@ See `common.expectWarning()` for usage.
|
|||||||
Indicates whether 'opensslCli' is supported.
|
Indicates whether 'opensslCli' is supported.
|
||||||
|
|
||||||
### platformTimeout(ms)
|
### platformTimeout(ms)
|
||||||
* `ms` [<number>]
|
* `ms` [<number>|<bigint>]
|
||||||
* return [<number>]
|
* return [<number>|<bigint>]
|
||||||
|
|
||||||
Platform normalizes timeout.
|
Returns a timeout value based on detected conditions. For example, a debug build
|
||||||
|
may need extra time so the returned value will be larger than on a release
|
||||||
|
build.
|
||||||
|
|
||||||
### PIPE
|
### PIPE
|
||||||
* [<string>]
|
* [<string>]
|
||||||
|
@ -187,14 +187,20 @@ const pwdCommand = isWindows ?
|
|||||||
|
|
||||||
|
|
||||||
function platformTimeout(ms) {
|
function platformTimeout(ms) {
|
||||||
|
// ESLint will not support 'bigint' in valid-typeof until it reaches stage 4.
|
||||||
|
// See https://github.com/eslint/eslint/pull/9636.
|
||||||
|
// eslint-disable-next-line valid-typeof
|
||||||
|
const multipliers = typeof ms === 'bigint' ?
|
||||||
|
{ two: 2n, four: 4n, seven: 7n } : { two: 2, four: 4, seven: 7 };
|
||||||
|
|
||||||
if (process.features.debug)
|
if (process.features.debug)
|
||||||
ms = 2 * ms;
|
ms = multipliers.two * ms;
|
||||||
|
|
||||||
if (global.__coverage__)
|
if (global.__coverage__)
|
||||||
ms = 4 * ms;
|
ms = multipliers.four * ms;
|
||||||
|
|
||||||
if (isAIX)
|
if (isAIX)
|
||||||
return 2 * ms; // default localhost speed is slower on AIX
|
return multipliers.two * ms; // default localhost speed is slower on AIX
|
||||||
|
|
||||||
if (process.arch !== 'arm')
|
if (process.arch !== 'arm')
|
||||||
return ms;
|
return ms;
|
||||||
@ -202,10 +208,10 @@ function platformTimeout(ms) {
|
|||||||
const armv = process.config.variables.arm_version;
|
const armv = process.config.variables.arm_version;
|
||||||
|
|
||||||
if (armv === '6')
|
if (armv === '6')
|
||||||
return 7 * ms; // ARMv6
|
return multipliers.seven * ms; // ARMv6
|
||||||
|
|
||||||
if (armv === '7')
|
if (armv === '7')
|
||||||
return 2 * ms; // ARMv7
|
return multipliers.two * ms; // ARMv7
|
||||||
|
|
||||||
return ms; // ARMv8+
|
return ms; // ARMv8+
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ prefix known_issues
|
|||||||
[$system==win32]
|
[$system==win32]
|
||||||
|
|
||||||
[$system==linux]
|
[$system==linux]
|
||||||
test-vm-timeout-escape-nexttick: PASS,FLAKY
|
|
||||||
test-vm-timeout-escape-promise: PASS,FLAKY
|
test-vm-timeout-escape-promise: PASS,FLAKY
|
||||||
test-vm-timeout-escape-queuemicrotask: PASS,FLAKY
|
test-vm-timeout-escape-queuemicrotask: PASS,FLAKY
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// Promises, nextTick, and queueMicrotask allow code to escape the timeout
|
// Promises, nextTick, and queueMicrotask allow code to escape the timeout
|
||||||
// set for runInContext, runInNewContext, and runInThisContext
|
// set for runInContext, runInNewContext, and runInThisContext
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
|
||||||
@ -13,12 +13,14 @@ const NS_PER_MS = 1000000n;
|
|||||||
const hrtime = process.hrtime.bigint;
|
const hrtime = process.hrtime.bigint;
|
||||||
const nextTick = process.nextTick;
|
const nextTick = process.nextTick;
|
||||||
|
|
||||||
|
const waitDuration = common.platformTimeout(100n);
|
||||||
|
|
||||||
function loop() {
|
function loop() {
|
||||||
const start = hrtime();
|
const start = hrtime();
|
||||||
while (1) {
|
while (1) {
|
||||||
const current = hrtime();
|
const current = hrtime();
|
||||||
const span = (current - start) / NS_PER_MS;
|
const span = (current - start) / NS_PER_MS;
|
||||||
if (span >= 100n) {
|
if (span >= waitDuration) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`escaped timeout at ${span} milliseconds!`);
|
`escaped timeout at ${span} milliseconds!`);
|
||||||
}
|
}
|
||||||
@ -33,9 +35,8 @@ assert.throws(() => {
|
|||||||
nextTick,
|
nextTick,
|
||||||
loop
|
loop
|
||||||
},
|
},
|
||||||
{ timeout: 5 }
|
{ timeout: common.platformTimeout(5) }
|
||||||
);
|
);
|
||||||
}, {
|
}, {
|
||||||
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT',
|
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT'
|
||||||
message: 'Script execution timed out after 5ms'
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user