Skip to content

Commit

Permalink
test: fix flaky timers-block-eventloop test
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
apapirovski authored and MylesBorins committed Feb 21, 2018
1 parent 804393b commit 5d54a04
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions test/sequential/test-timers-block-eventloop.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
'use strict';

const common = require('../common');
const fs = require('fs');
const platformTimeout = common.platformTimeout;
const assert = require('assert');

let called = false;
const t1 = setInterval(() => {
common.busyLoop(platformTimeout(12));
}, platformTimeout(10));

const t2 = setInterval(() => {
common.busyLoop(platformTimeout(15));
}, platformTimeout(10));

const t3 =
setTimeout(common.mustNotCall('eventloop blocked!'), platformTimeout(200));

setTimeout(function() {
fs.stat('/dev/nonexistent', () => {
assert(!called);
called = true;
setImmediate(common.mustCall(() => {
clearInterval(t1);
clearInterval(t2);
clearTimeout(t3);
});
}, platformTimeout(50));
}));
}, 10);

const t2 = setInterval(() => {
common.busyLoop(20);
}, 10);

0 comments on commit 5d54a04

Please sign in to comment.