Skip to content

Commit 788541b

Browse files
mcornacrvagg
authored andcommitted
test: fix race condition in unrefd interval test
Rely more on timers implementation rather than arbitrary timeouts. Refs: #1781 PR-URL: #3550 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent e129d83 commit 788541b

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎test/parallel/test-timers-unrefd-interval-still-fires.js‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
/*
33
* This test is a regression test for joyent/node#8900.
44
*/
5-
require('../common');
6-
varassert=require('assert');
5+
constcommon=require('../common');
6+
constassert=require('assert');
77

8-
varN=5;
8+
constTEST_DURATION=common.platformTimeout(100);
9+
constN=5;
910
varnbIntervalFired=0;
10-
vartimer=setInterval(function(){
11+
12+
constkeepOpen=setTimeout(()=>{
13+
console.error('[FAIL] Interval fired %d/%d times.',nbIntervalFired,N);
14+
thrownewError('Test timed out. keepOpen was not canceled.');
15+
},TEST_DURATION);
16+
17+
consttimer=setInterval(()=>{
1118
++nbIntervalFired;
12-
if(nbIntervalFired===N)
19+
if(nbIntervalFired===N){
1320
clearInterval(timer);
21+
timer._onTimeout=()=>{
22+
thrownewError('Unrefd interval fired after being cleared.');
23+
};
24+
setImmediate(()=>clearTimeout(keepOpen));
25+
}
1426
},1);
1527

1628
timer.unref();
17-
18-
setTimeout(functiononTimeout(){
19-
assert.strictEqual(nbIntervalFired,N);
20-
},100);

0 commit comments

Comments
 (0)