-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
CI: https://ci.nodejs.org/job/node-test-commit/1640/ Stress test with current implementation: https://ci.nodejs.org/job/node-stress-single-test/307/nodes=smartos14-64/console Stress test with version in this PR: https://ci.nodejs.org/job/node-stress-single-test/311/nodes=smartos14-64/console |
We aren't parallelizing in CI still, I think? I'm not really sure how these machines could have that much load on them... cc @nodejs/build these machines aren't shared with anyone else, right? |
timer._onTimeout = () => { | ||
throw new Error('Unrefd interval fired after being cleared.'); | ||
}; | ||
setImmediate(() => clearTimeout(keepOpen)); |
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.
This logic should not be removed. It allows the test to exit "early" if the test passed, rather than waiting for the entire keepOpen
interval.
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.
It still exits early thanks to the clearInterval(keepOpen)
call. The removed code above is not necessary to exit early.
Remove arbitrary timeout duration. This is a functionality test and not a performance benchmark. Rely on test runner timeout. Confirmed that the test (with ES6-isms removed) hangs/times out in Node 0.10.34 (which has the bug that this test is supposed to catch) and passes in 0.10.35 (which has the fix). So that is good. Fixes: nodejs#4559
Rebased against master and force-pushed. The diff is now one or two lines smaller. PTAL |
++nbIntervalFired; | ||
if (nbIntervalFired === N) { | ||
clearInterval(timer); | ||
timer._onTimeout = () => { | ||
throw new Error('Unrefd interval fired after being cleared.'); | ||
}; |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
You're not wrong, but at the same time:
- Without that code, the test times out if the
clearInterval()
somehow doesn't work. So it's not strictly necessary. - Presumably other tests check to confirm that
clearInterval()
works, so tacking it on to this test is kinda sorta scope creep. - If the test is for one thing and one thing only, it's a whole lot easier to figure out what's wrong when the test fails.
- Minor point, but the access to a
_
-prefixed property is kind of a code smell.
But you're not wrong on your point that the removed code provides a proper error if clearInterval()
does somehow fail. Happy to put it back in if it's a deal-breaker.
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.
shrug I have a suspicion there are not necessarily other tests which check that clearInterval()
works with unref timers.
-1, we don't |
For tests written for regressions in specific versions of Node.js that don't support certain ES6 features, it may be beneficial to un-ES6. Otherwise, we operate on faith that the test is still testing what it is supposed to test. Of course, the downside is being handcuffed on new features in that test. So, you know, I can see both sides... |
This isn't very solid, where do we the draw the line? Should we just disable ES6 in tests? |
I don't know that we'd need to get too strict about it, but if you want to draw a line, you do it like this: Presumably, each test has a version in which it should first succeed. It should fail in the version immediately prior to that. That test should be kept runnable in those versions. So tests that get written today for stuff that's broken (or features that don't exist) in version 5.4.1 can totally use arrow functions. But tests that were written for bugs in Node 0.10.4? Not so much. Given the state of the test suite, I'd be inclined to treat that as a guideline, though. |
Closing because consensus is not coalescing around this. |
So, interestingly, these are the tests that fail if you make an error like this test is supposed to catch, but in regular timers:
|
@Fishrock123 Can you elaborate a bit on this? I'm not sure what you mean. Do you mean that if the fix (that this test was written for) is removed from the source code, all these other tests fail as well? Which then suggests that this test might be entirely unnecessary? |
@Trott No, this what will happen if you apply the problem to regular (not unrefed) timeouts. |
@Fishrock123 I don't understand. I suspect I'm misunderstanding something elementary in your comment. Here's how I'm thinking about it: This test confirms that unrefed timers still fire. When you say "apply the problem to regular (not unrefed) timeouts", I'm not sure what the problem is that would apply to non-unrefed timers. Because surely non-unrefed timers should fire or else almost every timer test would fail. So you can't mean "Here are the tests that fail if timers don't fire." That doesn't seem likely to be what you mean. So what am I misunderstanding? |
Fix: #5351 Refs: #4561 PR-URL: #5352 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Fix: #5351 Refs: #4561 PR-URL: #5352 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Fix: #5351 Refs: #4561 PR-URL: #5352 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Fix: #5351 Refs: #4561 PR-URL: #5352 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
Remove arbitrary timeout duration. This is a functionality test and not
a performance benchmark. Rely on test runner timeout.
Confirmed that the test (with ES6-isms removed) hangs/times out in Node
0.10.34 (which has the bug that this test is supposed to catch) and
passes in 0.10.35 (which has the fix). So that is good.
Fixes: #4559
Refs: #3550
R=@thealphanerd
R=@Fishrock123
R=@misterdjules