From f0d58291d4d72ccffcf1ee68caa3135ea2006497 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 7 Nov 2018 14:40:35 -0800 Subject: [PATCH] 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 --- test/common/README.md | 8 +++++--- test/common/index.js | 16 +++++++++++----- test/known_issues/known_issues.status | 1 - .../test-vm-timeout-escape-nexttick.js | 11 ++++++----- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/common/README.md b/test/common/README.md index afc267ba7cb16c..f0bcced82e6149 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -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>] diff --git a/test/common/index.js b/test/common/index.js index da5027af135f0e..7b668e58c48ead 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -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+ } diff --git a/test/known_issues/known_issues.status b/test/known_issues/known_issues.status index 5a1ab289280d23..2a5514920b27bb 100644 --- a/test/known_issues/known_issues.status +++ b/test/known_issues/known_issues.status @@ -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 diff --git a/test/known_issues/test-vm-timeout-escape-nexttick.js b/test/known_issues/test-vm-timeout-escape-nexttick.js index 8afe2fb8cebb15..814da178fb2f78 100644 --- a/test/known_issues/test-vm-timeout-escape-nexttick.js +++ b/test/known_issues/test-vm-timeout-escape-nexttick.js @@ -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' });