-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: do not exit when only unref'd timer is present in test code #3825
Conversation
@rolfl, can you give this code a try? |
I note that |
@boneskull - I pulled your branch in to my local copy of mocha, I then npm link'd it in to my own project's npm repo, and ran the tests that initially caused my failues, in both normal, and debug mode, using webstorm to do it. (i.e. the worst case scenario). I also ran individual tests as selected from the WebStorm UI that uses the I can (happily) report a success. It ran all tests and skipped none (and these things were failing before). |
How/when is the timeout cleared? |
Unfortunately there's more to be done here. My guess is there's a problem with |
@boneskull - I ran in to the unit tests here hanging with --timeout 0 - as I mentioned in #3817. It may help you narrow down the issue... maybe. https://github.com/mochajs/mocha/blob/master/test/unit/mocha.spec.js#L281 |
what I'm seeing is a hang in the |
…3817 Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
603da44
to
399f813
Compare
alright, think I fixed that problem. |
I'm going to sit on this until I get at least one review |
out of topic: when debugging with VSCode, the CL input looks like this: This way the Nevertheless docu states:
|
When I run 'use strict';
it('just kind of stops', function(done) {
setTimeout(done, 10).unref();
});
it('just kind of stops', function(done) {
setTimeout(done, 10).unref();
}); the output is:
while debugging the same code, the output contains additional duration information:
|
This solution sets a timer for each individual test. Just as if user would call I would prefer a root timer, similar to the one proposed by @rolfl. In "Mocha.prototype.run": var runner = new exports.Runner(suite, options.delay);
var setTimeout = global.setTimeout;
if (suite._timeout === 0) {
runner.rootTimer = setTimeout(function() {}, 999999);
}
|
I'd have to see this working to be convinced it's the right choice. UPDATE: Let me clarify.
This PR sticks to the "status quo", so I'm more comfortable with this strategy. |
This is "slow" output. People using I wouldn't be opposed to updating the default value of |
This is why the debuggers which, when creating a "Mocha" debug profile, use The documentation is technically correct, but it might be worth mentioning that this only applies when executing |
@boneskull - re:
In all my testing with the solution I proposed (using an interval instead of a timeout to avoid the 24-day limit) it works really well except for in the base |
@rolfl I can't see what you did, but you can't just use |
@juergba Would like to know if you are insistent on a "global" timer? |
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.
@juergba Would like to know if you are insistent on a "global" timer?
No, I don't insist.
I note that _enableTimeouts is essentially a useless, internal flag that could be removed (across several different files) if we assume a timeout value of 0 is false and anything else is true.
As I understood we need now both properties. In our unref()
case here, timeout
is set to MAX_TIMEOUT and _enableTimeouts
remains false
.
BTW just noted, there is a very old branch about that issue: ead3576 |
In the timeout-handling code in
Runnable#resetTimeout
, if_enableTimeouts
wasfalse
, Mocha would completely avoid setting a timer, even if the timeout was set to0
.This PR changes the behavior so that a timer is always set, regardless of
_enableTimeouts
. If the test timeout value is0
, we set it to the maximum delay value (docs).Even if you happen to leave Mocha running in your debugger for longer than 24.8 days, the timer will just reset itself instead of throw a timeout error. Talk about corner cases...UPDATE: Resetting the timeout is problematic if timeouts are disabled after the timeout is reset. We don't really need this behavior anyway.
Fixes #3817.