Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
test: clear timeout on last unrefd interval fire
  • Loading branch information
mcornac committed Nov 9, 2015
commit 06d1980353ce26ca1cca5b79cde6b34d40af71d5
34 changes: 17 additions & 17 deletions test/parallel/test-timers-unrefd-interval-still-fires.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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();

var checkInterval = 100;
var maxNbChecks = 5;
var nbChecks = 1;
setTimeout(function check() {
if (nbChecks >= maxNbChecks || nbIntervalFired == N) {
assert.strictEqual(nbIntervalFired, N);
return;
}
++nbChecks;
setTimeout(check, checkInterval);
}, checkInterval);