Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions test/parallel/test-timers-unrefd-interval-still-fires.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 Is this the change you had in mind or should I also not clear the keepOpen timeout to give the error a chance to happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe wrap clearInterval in setImmediate()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

throw new Error('Unrefd interval fired after being cleared.');
};
setImmediate(() => clearTimeout(keepOpen));
}
}, 1);

timer.unref();

setTimeout(function onTimeout() {
assert.strictEqual(nbIntervalFired, N);
}, 100);