Skip to content

Commit ab8edc9

Browse files
apapirovskigibfahn
authored andcommitted
test: fix flaky timers-block-eventloop test
Due to extensive reliance on timings and the fs module, this test is currently inherently flaky. Refactor it to simply use setImmediate and only one busy loop. PR-URL: #18567 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent f8ad381 commit ab8edc9

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed
+11-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
'use strict';
22

33
const common = require('../common');
4-
const fs = require('fs');
5-
const platformTimeout = common.platformTimeout;
4+
const assert = require('assert');
65

6+
let called = false;
77
const t1 = setInterval(() => {
8-
common.busyLoop(platformTimeout(12));
9-
}, platformTimeout(10));
10-
11-
const t2 = setInterval(() => {
12-
common.busyLoop(platformTimeout(15));
13-
}, platformTimeout(10));
14-
15-
const t3 =
16-
setTimeout(common.mustNotCall('eventloop blocked!'), platformTimeout(200));
17-
18-
setTimeout(function() {
19-
fs.stat('/dev/nonexistent', () => {
8+
assert(!called);
9+
called = true;
10+
setImmediate(common.mustCall(() => {
2011
clearInterval(t1);
2112
clearInterval(t2);
22-
clearTimeout(t3);
23-
});
24-
}, platformTimeout(50));
13+
}));
14+
}, 10);
15+
16+
const t2 = setInterval(() => {
17+
common.busyLoop(20);
18+
}, 10);

0 commit comments

Comments
 (0)