0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

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:
Rich Trott 2018-11-07 14:40:35 -08:00
parent 5c59622243
commit d8e06b23b0
4 changed files with 22 additions and 14 deletions

View File

@ -271,10 +271,12 @@ See `common.expectWarning()` for usage.
Indicates whether 'opensslCli' is supported.
### platformTimeout(ms)
* `ms` [&lt;number>]
* return [&lt;number>]
* `ms` [&lt;number>|&lt;bigint>]
* return [&lt;number>|&lt;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
* [&lt;string>]

View File

@ -187,14 +187,20 @@ const pwdCommand = isWindows ?
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)
ms = 2 * ms;
ms = multipliers.two * ms;
if (global.__coverage__)
ms = 4 * ms;
ms = multipliers.four * ms;
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')
return ms;
@ -202,10 +208,10 @@ function platformTimeout(ms) {
const armv = process.config.variables.arm_version;
if (armv === '6')
return 7 * ms; // ARMv6
return multipliers.seven * ms; // ARMv6
if (armv === '7')
return 2 * ms; // ARMv7
return multipliers.two * ms; // ARMv7
return ms; // ARMv8+
}

View File

@ -9,7 +9,6 @@ prefix known_issues
[$system==win32]
[$system==linux]
test-vm-timeout-escape-nexttick: PASS,FLAKY
test-vm-timeout-escape-promise: PASS,FLAKY
test-vm-timeout-escape-queuemicrotask: PASS,FLAKY

View File

@ -4,7 +4,7 @@
// Promises, nextTick, and queueMicrotask allow code to escape the timeout
// set for runInContext, runInNewContext, and runInThisContext
require('../common');
const common = require('../common');
const assert = require('assert');
const vm = require('vm');
@ -13,12 +13,14 @@ const NS_PER_MS = 1000000n;
const hrtime = process.hrtime.bigint;
const nextTick = process.nextTick;
const waitDuration = common.platformTimeout(100n);
function loop() {
const start = hrtime();
while (1) {
const current = hrtime();
const span = (current - start) / NS_PER_MS;
if (span >= 100n) {
if (span >= waitDuration) {
throw new Error(
`escaped timeout at ${span} milliseconds!`);
}
@ -33,9 +35,8 @@ assert.throws(() => {
nextTick,
loop
},
{ timeout: 5 }
{ timeout: common.platformTimeout(5) }
);
}, {
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT',
message: 'Script execution timed out after 5ms'
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT'
});