Skip to content

Commit

Permalink
test: remove common.busyLoop()
Browse files Browse the repository at this point in the history
This commit replaces common.busyLoop() with sleep().

PR-URL: #30787
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
cjihrig authored and targos committed Dec 9, 2019
1 parent dc69cbe commit a574cb0
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
5 changes: 0 additions & 5 deletions test/common/README.md
Expand Up @@ -45,11 +45,6 @@ tasks.

Takes `whitelist` and concats that with predefined `knownGlobals`.

### busyLoop(time)
* `time` [&lt;number>][]

Blocks for `time` amount of time.

### canCreateSymLink()
* return [&lt;boolean>][]

Expand Down
7 changes: 0 additions & 7 deletions test/common/index.js
Expand Up @@ -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) {
try {
process.kill(pid, 'SIGCONT');
Expand Down Expand Up @@ -744,7 +738,6 @@ function runWithInvalidFD(func) {
module.exports = {
allowGlobals,
buildType,
busyLoop,
canCreateSymLink,
childShouldThrowAndAbort,
createZeroFilledFile,
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.mjs
Expand Up @@ -39,7 +39,6 @@ const {
skip,
ArrayStream,
nodeProcessAborted,
busyLoop,
isAlive,
expectWarning,
expectsError,
Expand Down Expand Up @@ -86,7 +85,6 @@ export {
skip,
ArrayStream,
nodeProcessAborted,
busyLoop,
isAlive,
expectWarning,
expectsError,
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-timers-nested.js
@@ -1,7 +1,9 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');
const { sleep } = require('internal/util');

// 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
Expand All @@ -23,7 +25,7 @@ scenarios.forEach(function(delay) {

// Busy loop for the same timeout used for the nested timer to ensure that
// 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
// after A but before the next iteration of the libuv event loop.
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-timers-next-tick.js
@@ -1,6 +1,8 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const { sleep } = require('internal/util');

// This test verifies that the next tick queue runs after each
// individual Timeout, as well as each individual Immediate.
Expand All @@ -16,7 +18,7 @@ const t2 = setTimeout(common.mustNotCall(), 1);
const t3 = setTimeout(common.mustNotCall(), 1);
setTimeout(common.mustCall(), 1);

common.busyLoop(5);
sleep(5);

setImmediate(common.mustCall(() => {
process.nextTick(() => {
Expand Down
5 changes: 3 additions & 2 deletions test/sequential/test-performance-eventloopdelay.js
@@ -1,11 +1,12 @@
// Flags: --expose-gc
// Flags: --expose-gc --expose-internals
'use strict';

const common = require('../common');
const assert = require('assert');
const {
monitorEventLoopDelay
} = require('perf_hooks');
const { sleep } = require('internal/util');

{
const histogram = monitorEventLoopDelay();
Expand Down Expand Up @@ -54,7 +55,7 @@ const {
histogram.enable();
let m = 5;
function spinAWhile() {
common.busyLoop(1000);
sleep(1000);
if (--m > 0) {
setTimeout(spinAWhile, common.platformTimeout(500));
} else {
Expand Down
4 changes: 3 additions & 1 deletion test/sequential/test-timers-block-eventloop.js
@@ -1,7 +1,9 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const assert = require('assert');
const { sleep } = require('internal/util');

let called = false;
const t1 = setInterval(() => {
Expand All @@ -14,5 +16,5 @@ const t1 = setInterval(() => {
}, 10);

const t2 = setInterval(() => {
common.busyLoop(20);
sleep(20);
}, 10);
4 changes: 3 additions & 1 deletion test/sequential/test-timers-blocking-callback.js
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';

/*
Expand Down Expand Up @@ -25,6 +26,7 @@

const common = require('../common');
const assert = require('assert');
const { sleep } = require('internal/util');

const TIMEOUT = 100;

Expand Down Expand Up @@ -65,7 +67,7 @@ function blockingCallback(retry, callback) {
return callback();
} else {
// Block by busy-looping to trigger the issue
common.busyLoop(TIMEOUT);
sleep(TIMEOUT);

timeCallbackScheduled = Date.now();
setTimeout(blockingCallback.bind(null, retry, callback), TIMEOUT);
Expand Down
@@ -1,13 +1,15 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const { sleep } = require('internal/util');

let cntr = 0;
let first;
const t = setInterval(() => {
cntr++;
if (cntr === 1) {
common.busyLoop(100);
sleep(100);
// Ensure that the event loop passes before the second interval
setImmediate(() => assert.strictEqual(cntr, 1));
first = Date.now();
Expand Down

0 comments on commit a574cb0

Please sign in to comment.