mirror of https://github.com/nodejs/node.git
test: remove common.busyLoop()
This commit replaces common.busyLoop() with sleep(). PR-URL: https://github.com/nodejs/node/pull/30787 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
f446929923
commit
aa363c49ea
|
@ -45,11 +45,6 @@ tasks.
|
||||||
|
|
||||||
Takes `whitelist` and concats that with predefined `knownGlobals`.
|
Takes `whitelist` and concats that with predefined `knownGlobals`.
|
||||||
|
|
||||||
### busyLoop(time)
|
|
||||||
* `time` [<number>][]
|
|
||||||
|
|
||||||
Blocks for `time` amount of time.
|
|
||||||
|
|
||||||
### canCreateSymLink()
|
### canCreateSymLink()
|
||||||
* return [<boolean>][]
|
* return [<boolean>][]
|
||||||
|
|
||||||
|
|
|
@ -481,12 +481,6 @@ function nodeProcessAborted(exitCode, signal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function busyLoop(time) {
|
|
||||||
const startTime = Date.now();
|
|
||||||
const stopTime = startTime + time;
|
|
||||||
while (Date.now() < stopTime) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAlive(pid) {
|
function isAlive(pid) {
|
||||||
try {
|
try {
|
||||||
process.kill(pid, 'SIGCONT');
|
process.kill(pid, 'SIGCONT');
|
||||||
|
@ -744,7 +738,6 @@ function runWithInvalidFD(func) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
allowGlobals,
|
allowGlobals,
|
||||||
buildType,
|
buildType,
|
||||||
busyLoop,
|
|
||||||
canCreateSymLink,
|
canCreateSymLink,
|
||||||
childShouldThrowAndAbort,
|
childShouldThrowAndAbort,
|
||||||
createZeroFilledFile,
|
createZeroFilledFile,
|
||||||
|
|
|
@ -39,7 +39,6 @@ const {
|
||||||
skip,
|
skip,
|
||||||
ArrayStream,
|
ArrayStream,
|
||||||
nodeProcessAborted,
|
nodeProcessAborted,
|
||||||
busyLoop,
|
|
||||||
isAlive,
|
isAlive,
|
||||||
expectWarning,
|
expectWarning,
|
||||||
expectsError,
|
expectsError,
|
||||||
|
@ -86,7 +85,6 @@ export {
|
||||||
skip,
|
skip,
|
||||||
ArrayStream,
|
ArrayStream,
|
||||||
nodeProcessAborted,
|
nodeProcessAborted,
|
||||||
busyLoop,
|
|
||||||
isAlive,
|
isAlive,
|
||||||
expectWarning,
|
expectWarning,
|
||||||
expectsError,
|
expectsError,
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
// Make sure we test 0ms timers, since they would had always wanted to run on
|
// Make sure we test 0ms timers, since they would had always wanted to run on
|
||||||
// the current tick, and greater than 0ms timers, for scenarios where the
|
// the current tick, and greater than 0ms timers, for scenarios where the
|
||||||
|
@ -23,7 +25,7 @@ scenarios.forEach(function(delay) {
|
||||||
|
|
||||||
// Busy loop for the same timeout used for the nested timer to ensure that
|
// Busy loop for the same timeout used for the nested timer to ensure that
|
||||||
// we are in fact expiring the nested timer.
|
// we are in fact expiring the nested timer.
|
||||||
common.busyLoop(delay);
|
sleep(delay);
|
||||||
|
|
||||||
// The purpose of running this assert in nextTick is to make sure it runs
|
// The purpose of running this assert in nextTick is to make sure it runs
|
||||||
// after A but before the next iteration of the libuv event loop.
|
// after A but before the next iteration of the libuv event loop.
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
// This test verifies that the next tick queue runs after each
|
// This test verifies that the next tick queue runs after each
|
||||||
// individual Timeout, as well as each individual Immediate.
|
// individual Timeout, as well as each individual Immediate.
|
||||||
|
@ -16,7 +18,7 @@ const t2 = setTimeout(common.mustNotCall(), 1);
|
||||||
const t3 = setTimeout(common.mustNotCall(), 1);
|
const t3 = setTimeout(common.mustNotCall(), 1);
|
||||||
setTimeout(common.mustCall(), 1);
|
setTimeout(common.mustCall(), 1);
|
||||||
|
|
||||||
common.busyLoop(5);
|
sleep(5);
|
||||||
|
|
||||||
setImmediate(common.mustCall(() => {
|
setImmediate(common.mustCall(() => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Flags: --expose-gc
|
// Flags: --expose-gc --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
@ -6,6 +6,7 @@ const assert = require('assert');
|
||||||
const {
|
const {
|
||||||
monitorEventLoopDelay
|
monitorEventLoopDelay
|
||||||
} = require('perf_hooks');
|
} = require('perf_hooks');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
{
|
{
|
||||||
const histogram = monitorEventLoopDelay();
|
const histogram = monitorEventLoopDelay();
|
||||||
|
@ -54,7 +55,7 @@ const {
|
||||||
histogram.enable();
|
histogram.enable();
|
||||||
let m = 5;
|
let m = 5;
|
||||||
function spinAWhile() {
|
function spinAWhile() {
|
||||||
common.busyLoop(1000);
|
sleep(1000);
|
||||||
if (--m > 0) {
|
if (--m > 0) {
|
||||||
setTimeout(spinAWhile, common.platformTimeout(500));
|
setTimeout(spinAWhile, common.platformTimeout(500));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
let called = false;
|
let called = false;
|
||||||
const t1 = setInterval(() => {
|
const t1 = setInterval(() => {
|
||||||
|
@ -14,5 +16,5 @@ const t1 = setInterval(() => {
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
||||||
const t2 = setInterval(() => {
|
const t2 = setInterval(() => {
|
||||||
common.busyLoop(20);
|
sleep(20);
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
const TIMEOUT = 100;
|
const TIMEOUT = 100;
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ function blockingCallback(retry, callback) {
|
||||||
return callback();
|
return callback();
|
||||||
} else {
|
} else {
|
||||||
// Block by busy-looping to trigger the issue
|
// Block by busy-looping to trigger the issue
|
||||||
common.busyLoop(TIMEOUT);
|
sleep(TIMEOUT);
|
||||||
|
|
||||||
timeCallbackScheduled = Date.now();
|
timeCallbackScheduled = Date.now();
|
||||||
setTimeout(blockingCallback.bind(null, retry, callback), TIMEOUT);
|
setTimeout(blockingCallback.bind(null, retry, callback), TIMEOUT);
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { sleep } = require('internal/util');
|
||||||
|
|
||||||
let cntr = 0;
|
let cntr = 0;
|
||||||
let first;
|
let first;
|
||||||
const t = setInterval(() => {
|
const t = setInterval(() => {
|
||||||
cntr++;
|
cntr++;
|
||||||
if (cntr === 1) {
|
if (cntr === 1) {
|
||||||
common.busyLoop(100);
|
sleep(100);
|
||||||
// Ensure that the event loop passes before the second interval
|
// Ensure that the event loop passes before the second interval
|
||||||
setImmediate(() => assert.strictEqual(cntr, 1));
|
setImmediate(() => assert.strictEqual(cntr, 1));
|
||||||
first = Date.now();
|
first = Date.now();
|
||||||
|
|
Loading…
Reference in New Issue