Skip to content

Commit a574cb0

Browse files
cjihrigtargos
authored andcommitted
test: remove common.busyLoop()
This commit replaces common.busyLoop() with sleep(). PR-URL: #30787 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent dc69cbe commit a574cb0

9 files changed

+20
-23
lines changed

test/common/README.md

-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ tasks.
4545

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

48-
### busyLoop(time)
49-
* `time` [&lt;number>][]
50-
51-
Blocks for `time` amount of time.
52-
5348
### canCreateSymLink()
5449
* return [&lt;boolean>][]
5550

test/common/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,6 @@ function nodeProcessAborted(exitCode, signal) {
481481
}
482482
}
483483

484-
function busyLoop(time) {
485-
const startTime = Date.now();
486-
const stopTime = startTime + time;
487-
while (Date.now() < stopTime) {}
488-
}
489-
490484
function isAlive(pid) {
491485
try {
492486
process.kill(pid, 'SIGCONT');
@@ -744,7 +738,6 @@ function runWithInvalidFD(func) {
744738
module.exports = {
745739
allowGlobals,
746740
buildType,
747-
busyLoop,
748741
canCreateSymLink,
749742
childShouldThrowAndAbort,
750743
createZeroFilledFile,

test/common/index.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const {
3939
skip,
4040
ArrayStream,
4141
nodeProcessAborted,
42-
busyLoop,
4342
isAlive,
4443
expectWarning,
4544
expectsError,
@@ -86,7 +85,6 @@ export {
8685
skip,
8786
ArrayStream,
8887
nodeProcessAborted,
89-
busyLoop,
9088
isAlive,
9189
expectWarning,
9290
expectsError,

test/parallel/test-timers-nested.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Flags: --expose-internals
12
'use strict';
23

3-
const common = require('../common');
4+
require('../common');
45
const assert = require('assert');
6+
const { sleep } = require('internal/util');
57

68
// Make sure we test 0ms timers, since they would had always wanted to run on
79
// the current tick, and greater than 0ms timers, for scenarios where the
@@ -23,7 +25,7 @@ scenarios.forEach(function(delay) {
2325

2426
// Busy loop for the same timeout used for the nested timer to ensure that
2527
// we are in fact expiring the nested timer.
26-
common.busyLoop(delay);
28+
sleep(delay);
2729

2830
// The purpose of running this assert in nextTick is to make sure it runs
2931
// after A but before the next iteration of the libuv event loop.

test/parallel/test-timers-next-tick.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
const common = require('../common');
5+
const { sleep } = require('internal/util');
46

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

19-
common.busyLoop(5);
21+
sleep(5);
2022

2123
setImmediate(common.mustCall(() => {
2224
process.nextTick(() => {

test/sequential/test-performance-eventloopdelay.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Flags: --expose-gc
1+
// Flags: --expose-gc --expose-internals
22
'use strict';
33

44
const common = require('../common');
55
const assert = require('assert');
66
const {
77
monitorEventLoopDelay
88
} = require('perf_hooks');
9+
const { sleep } = require('internal/util');
910

1011
{
1112
const histogram = monitorEventLoopDelay();
@@ -54,7 +55,7 @@ const {
5455
histogram.enable();
5556
let m = 5;
5657
function spinAWhile() {
57-
common.busyLoop(1000);
58+
sleep(1000);
5859
if (--m > 0) {
5960
setTimeout(spinAWhile, common.platformTimeout(500));
6061
} else {

test/sequential/test-timers-block-eventloop.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
const common = require('../common');
45
const assert = require('assert');
6+
const { sleep } = require('internal/util');
57

68
let called = false;
79
const t1 = setInterval(() => {
@@ -14,5 +16,5 @@ const t1 = setInterval(() => {
1416
}, 10);
1517

1618
const t2 = setInterval(() => {
17-
common.busyLoop(20);
19+
sleep(20);
1820
}, 10);

test/sequential/test-timers-blocking-callback.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
/*
@@ -25,6 +26,7 @@
2526

2627
const common = require('../common');
2728
const assert = require('assert');
29+
const { sleep } = require('internal/util');
2830

2931
const TIMEOUT = 100;
3032

@@ -65,7 +67,7 @@ function blockingCallback(retry, callback) {
6567
return callback();
6668
} else {
6769
// Block by busy-looping to trigger the issue
68-
common.busyLoop(TIMEOUT);
70+
sleep(TIMEOUT);
6971

7072
timeCallbackScheduled = Date.now();
7173
setTimeout(blockingCallback.bind(null, retry, callback), TIMEOUT);

test/sequential/test-timers-set-interval-excludes-callback-duration.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
// Flags: --expose-internals
12
'use strict';
2-
const common = require('../common');
3+
require('../common');
34
const assert = require('assert');
5+
const { sleep } = require('internal/util');
46

57
let cntr = 0;
68
let first;
79
const t = setInterval(() => {
810
cntr++;
911
if (cntr === 1) {
10-
common.busyLoop(100);
12+
sleep(100);
1113
// Ensure that the event loop passes before the second interval
1214
setImmediate(() => assert.strictEqual(cntr, 1));
1315
first = Date.now();

0 commit comments

Comments
 (0)