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 <rtrott@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent dc69cbe commit a574cb0

9 files changed

Lines changed: 20 additions & 23 deletions

‎test/common/README.md‎

Lines changed: 0 additions & 5 deletions
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‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,6 @@ function nodeProcessAborted(exitCode, signal) {
481481
}
482482
}
483483

484-
functionbusyLoop(time){
485-
conststartTime=Date.now();
486-
conststopTime=startTime+time;
487-
while(Date.now()<stopTime){}
488-
}
489-
490484
functionisAlive(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‎

Lines changed: 0 additions & 2 deletions
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‎

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

3-
constcommon=require('../common');
4+
require('../common');
45
constassert=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‎

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

34
constcommon=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
constt3=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‎

Lines changed: 3 additions & 2 deletions
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
constcommon=require('../common');
55
constassert=require('assert');
66
const{
77
monitorEventLoopDelay
88
}=require('perf_hooks');
9+
const{ sleep }=require('internal/util');
910

1011
{
1112
consthistogram=monitorEventLoopDelay();
@@ -54,7 +55,7 @@ const {
5455
histogram.enable();
5556
letm=5;
5657
functionspinAWhile(){
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‎

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

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

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

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

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

Lines changed: 3 additions & 1 deletion
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
constcommon=require('../common');
2728
constassert=require('assert');
29+
const{ sleep }=require('internal/util');
2830

2931
constTIMEOUT=100;
3032

@@ -65,7 +67,7 @@ function blockingCallback(retry, callback) {
6567
returncallback();
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‎

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

57
letcntr=0;
68
letfirst;
79
constt=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)