node/test/known_issues/test-vm-timeout-escape-nexttick.js
Santiago Gimeno 1620626fa8 test: unflake test-vm-timeout-escape-nexttick
This wasn't failing on arm boxes, increase the `runInNewContext()`
timeout a bit to make sure the code it's allowed to fail.

PR-URL: https://github.com/nodejs/node/pull/48078
Fixes: https://github.com/nodejs/node/issues/43931
Fixes: https://github.com/nodejs/node/issues/42496
Fixes: https://github.com/nodejs/node/issues/47715
Fixes: https://github.com/nodejs/node/issues/47259
Fixes: https://github.com/nodejs/node/issues/47241
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2023-05-24 11:07:06 +00:00

47 lines
1.1 KiB
JavaScript

'use strict';
// https://github.com/nodejs/node/issues/3020
// Promises, nextTick, and queueMicrotask allow code to escape the timeout
// set for runInContext, runInNewContext, and runInThisContext
const common = require('../common');
const assert = require('assert');
const vm = require('vm');
const NS_PER_MS = 1000000n;
const hrtime = process.hrtime.bigint;
const nextTick = process.nextTick;
const waitDuration = common.platformTimeout(200n);
function loop() {
const start = hrtime();
while (1) {
const current = hrtime();
const span = (current - start) / NS_PER_MS;
if (span >= waitDuration) {
throw new Error(
`escaped timeout at ${span} milliseconds!`);
}
}
}
// The bug won't happen 100% reliably so run the test a small number of times to
// make sure we catch it if the bug exists.
for (let i = 0; i < 4; i++) {
assert.throws(() => {
vm.runInNewContext(
'nextTick(loop); loop();',
{
hrtime,
nextTick,
loop,
},
{ timeout: common.platformTimeout(100) },
);
}, {
code: 'ERR_SCRIPT_EXECUTION_TIMEOUT',
});
}