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>
This commit is contained in:
parent
d01eb6882f
commit
6de82c69a0
@ -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…
x
Reference in New Issue
Block a user