-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fix test-timers-unrefd-interval-still-fires #4561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
'use strict'; | ||
/* | ||
* This test is a regression test for joyent/node#8900. | ||
* | ||
* Node.js 0.10.34 contains the bug that this test detects. | ||
* Node.js 0.10.35 contains the fix. | ||
* | ||
* Due to the introduction of ES6-isms, comment out `'use strict'` and | ||
* `require('../common');` to run the test on Node.js 0.10.x. | ||
*/ | ||
const common = require('../common'); | ||
require('../common'); | ||
|
||
const TEST_DURATION = common.platformTimeout(100); | ||
const N = 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives a proper error if the test times out. |
||
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 keepOpen = setInterval(function() {}, 9999); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really see how this is any less arbitrary. I guess we can up the duration to like 1s if it's really not solvable any other way, but 9s seems like overkill. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's less arbitrary because it is a |
||
|
||
const timer = setInterval(() => { | ||
const timer = setInterval(function() { | ||
++nbIntervalFired; | ||
if (nbIntervalFired === N) { | ||
clearInterval(timer); | ||
timer._onTimeout = () => { | ||
throw new Error('Unrefd interval fired after being cleared.'); | ||
}; | ||
clearTimeout(keepOpen); | ||
clearInterval(keepOpen); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines give a proper error for if too many timeouts occur. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're not wrong, but at the same time:
But you're not wrong on your point that the removed code provides a proper error if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shrug I have a suspicion there are not necessarily other tests which check that |
||
} | ||
}, 1); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be necessary. If testing is needed, you could just undo the timers fix: https://github.com/nodejs/node-v0.x-archive/pull/8906/files#diff-0a5d4868b2b9b17cf9e2c11f1bd1311eL296
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strictly necessary, but awfully nice. I'd rather
nvm use 0.10.34
and then test as opposed to undo a fix (and hope that the code is still in basically the same place so that I don't have to do any git archaeology or greps in the code base to find it), recompile, and test.