Skip to content

Commit

Permalink
test: fix flaky VM timeout test on Raspberry Pi
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trott authored and BridgeAR committed Nov 13, 2018
1 parent f669817 commit 415fcde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
8 changes: 5 additions & 3 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>]
Expand Down
16 changes: 11 additions & 5 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,31 @@ 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;

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+
}
Expand Down
1 change: 0 additions & 1 deletion test/known_issues/known_issues.status
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions test/known_issues/test-vm-timeout-escape-nexttick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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!`);
}
Expand All @@ -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'
});

0 comments on commit 415fcde

Please sign in to comment.