From ab8edc9d4844aaf66dcbad409415ffcc59c0aebc Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sun, 4 Feb 2018 16:49:00 -0500 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/18567 Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater --- .../sequential/test-timers-block-eventloop.js | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/test/sequential/test-timers-block-eventloop.js b/test/sequential/test-timers-block-eventloop.js index f6426e454e0882..811216fcb29e7d 100644 --- a/test/sequential/test-timers-block-eventloop.js +++ b/test/sequential/test-timers-block-eventloop.js @@ -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);