node/test/parallel/test-timers-unrefd-interval-still-fires.js
Rich Trott e071894202 test: fix flaky unrefed timers test
Remove unnecessary `setImmediate()` that causes a minor race condition.
Stop the test after 3 occurrences rather than 5 to allow for slower
hosts running the test in parallel with other tests.

Fixes: https://github.com/nodejs/node/issues/4559
PR-URL: https://github.com/nodejs/node/pull/4599
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2016-01-11 09:24:04 -08:00

28 lines
675 B
JavaScript

'use strict';
/*
* This test is a regression test for joyent/node#8900.
*/
const common = require('../common');
const TEST_DURATION = common.platformTimeout(100);
const N = 3;
var nbIntervalFired = 0;
const keepOpen = setTimeout(() => {
console.error('[FAIL] Interval fired %d/%d times.', nbIntervalFired, N);
throw new Error('Test timed out. keepOpen was not canceled.');
}, TEST_DURATION);
const timer = setInterval(() => {
++nbIntervalFired;
if (nbIntervalFired === N) {
clearInterval(timer);
timer._onTimeout = () => {
throw new Error('Unrefd interval fired after being cleared.');
};
clearTimeout(keepOpen);
}
}, 1);
timer.unref();