Browse Source

test: fix race condition in unrefd interval test

Rely more on timers implementation rather than arbitrary timeouts.

Refs: https://github.com/nodejs/node/issues/1781
PR-URL: https://github.com/nodejs/node/pull/3550

Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v5.x
Michael Cornacchia 9 years ago
committed by Rod Vagg
parent
commit
788541b40c
  1. 26
      test/parallel/test-timers-unrefd-interval-still-fires.js

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

@ -2,19 +2,27 @@
/*
* This test is a regression test for joyent/node#8900.
*/
require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');
var N = 5;
const TEST_DURATION = common.platformTimeout(100);
const N = 5;
var nbIntervalFired = 0;
var timer = setInterval(function() {
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)
if (nbIntervalFired === N) {
clearInterval(timer);
timer._onTimeout = () => {
throw new Error('Unrefd interval fired after being cleared.');
};
setImmediate(() => clearTimeout(keepOpen));
}
}, 1);
timer.unref();
setTimeout(function onTimeout() {
assert.strictEqual(nbIntervalFired, N);
}, 100);

Loading…
Cancel
Save