Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky VM timeout test on Raspberry Pi #24238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` [<number>]
* return [<number>]
* `ms` [<number>|<bigint>]
* 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
* [<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'
});