-
-
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
mocha 4 doesn't exit unlike mocha 3 #3044
Comments
I am seeing the exact same problem. Tests will pass and then mocha just hangs. See my Travis CI: I also noticed this same problem on video-dev/hls.js - mocha just hangs after passing tests: |
Did you guys read the release notes? https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit |
Thanks. tok bad the mocha website is not updated with this breaking change. The cli args there do not mention it. |
Other than providing a quick fix (use |
The release notes suggest using |
Hit by this too. I understand the reasoning behind the change to the default, and thank you for incrementing the major version, but given that |
Hi all, First off, I want to apologize for the rough upgrade path on this point -- we definitely agree that Mocha ought to tell the user what's keeping the tests running (and then it wouldn't even need to keep the process open; it could just be a reason to return failure after they're done), but haven't found an entirely satisfactory way to do so yet. Version 4 didn't get the amount of time we wanted to put into it, as it was prompted by our CI failing due to changes in PhantomJS 1.x's installer (package-lock.json probably would have prevented this if we'd had it set up beforehand, but we still can't get it working).
...so it's better than nothing (although I'll see if I can update the release notes to describe this in more detail), but if anyone knows a better option please let us know! Also sorry about missing the site documentation -- we'll get it updated as soon as possible. (Once #2987 is done we can even make it an automatic part of our version/publish scripting!) |
Edit: This works:
|
Right, sorry I wasn't clear about that -- |
Created mochajs/old-mochajs-site#81 and #3045 to track updating the documentation and Mocha's Node flags, respectively. Will keep this issue open at least till the documentation is updated. |
@ScottFreeCode you may want to mention that (is there a global "after" hook that mocha calls when all tests are complete?) In any event, I appreciate the help, and thanks for Mocha! |
Are you sure? I tested with Node 8.6.0. Albeit not on all OSes, so I guess I should fire up every box I have and triple-check... |
Here's a Gist with a rough guide to work around this for the time being. |
This "works" in that it triggers the output from the module, but it doesn't actually give me much information, regardless of the version of Node.js. I'm going to add some updates to the site, but please see my forthcoming comments on #3045. |
It gives a useful stacktrace for |
I suppose my general advice would be "if you're pulling your hair out, just add |
...and here are the docs |
Signed-off-by: Mario Kozjak <kozjakm1@gmail.com>
Sorry to comment on the closed PR again, but there might a user-friendly solution here: One could log a warning about the changed behavior after the runner has finished for 3s or so, but the process didn't exit. |
I’ve considered that but I’m wary that it will cause other problems with reporters or other integrations... I can’t prove it won’t. |
## Symptoms Upgrading to `mocha@5` now causes my tests to hang without any context. [See this Travis build as an example](https://travis-ci.org/mongodb-js/index-model/builds/451375910) ## Resolution We were *not* explicitly closing driver connections after tests that needed it finished which kept the driver's underlying sockets to remain open. These `after(client.close)` blocks have been added in this PR. ## Root Cause `mocha@4` introduced a reenforcement for better testing and quality with the removal of mocha killing its process when it *thinks* the tests complete. [See release notes](https://boneskull.com/mocha-v4-nears-release/#mochawontforceexit) For us, this is a huge win. `mocha` has always included its own process management which allowed us to play fast and loose releasing fds/sockets/timeouts/etc properly. ## Diagnosis Googling lead me to [this mocha issue](mochajs/mocha#3044) where the maintainer provides several solutions to debug this and make your tests even *more* correct. Here's what worked for me: ```bash npm i -g wtfnode; wtfnode ./node_modules/.bin/_mocha test/data-service.test.js; # Wait for hang to appear # Hit ctrl+c which produces the output below ``` ``` 34 passing (1s) ^C[WTF Node?] open handles: - File descriptors: (note: stdio always exists) - fd 1 (tty) (stdio) - fd 2 (tty) (stdio) - Sockets: - 127.0.0.1:57887 -> 127.0.0.1:27018 - 127.0.0.1:57888 -> 127.0.0.1:27018 - 127.0.0.1:57890 -> 127.0.0.1:27018 - 127.0.0.1:57891 -> 127.0.0.1:27018 - Timers: - (5000 ~ 5 s) (anonymous) @ /Users/lucas/data-service/node_modules/mongodb-core/lib/topologies/server.js:373 ```
Since v4 mocha doesn't force-exit if a process or a socket is still running. mochajs/mocha#3044
var timers = sinon.useFakeTimers({
now: new Date().getTime(),
shouldAdvanceTime: true,
}); If I forget |
Based on the documentation @pgilad sent here, to me there is a cleaner solution. As the documentaion says:
A cleaner solution then it would be to create a global
Then you can execute mocha tests like:
or
It is important that if you are using wildcards for the name of the tests files like I did with |
@vctr90 That's a great solution, although you have a period where you should have a comma in your example. Also the whole thing can be code golf-ed down to just:
Is there any chance a dev could chime in on why adding this to Mocha proper would hurt someone (because it would clearly help a lot of people)? |
@machineghost I like the new behavior for 2 reasons:
So when I run into this, this is an incentive for me to try and clean up my code so it doesn't happen. Your perspective on this might be 'i don't care about memory leaks', or 'this is not worth fixing in my application'. If you're in this category the easiest is to make a |
It just seems to me that this is about making more noise, not signal: in the significant majority of cases no one's app is going to get better because Mocha hung at the end. If Mocha is going to default, it seems like it should default to ending when tests (and all If people really want to debug unclosed connections then it seems that should be the case you provide an option for. But all the rest of the time, does it really benefit the library's users to confuse everyone else with (what amounts to saying) "you're in a testing environment and one of a billion possible things is open"? To put it another way, if you're going to tell 99% of the people that run into this "just use I mean, if you made that the option, realistically how often do you think people would even pass it? |
P.S. I just came across this: https://stackoverflow.com/questions/54999115/where-to-destroy-knex-connection. If you look at the second answer, this behavior in Mocha directly caused at least one user (who isn't me, and I swear I don't know them: I just found this by luck after making my last post) to add incorrect non-test code (this "feature" made them incorrectly think needed to call Summary version:
But to be clear, this user had a working environment, and because Mocha (essentially) told them their perfectly good code was wrong, they lost who knows how much time trying to solve the bug they created by destroying their connections. And that's just this one unlucky person who happened to do it in public, and who I happened to see. So, I guess what I'm trying to convey is, this isn't just about what's philosophically correct, nor is it just that some noise is obscuring useful signals ... this behavior is actually causing harm, and making programmers waste time tilting at windmills. |
I'm sorry, I mistook your tired point for an honest question. I regret answering. Maybe the developers can lock this thread. |
|
Is there a way to get the equivalent effect of using the I do not see a documented option for exit/noexit, nor a general way to pass in a flag string while using the NodeJS API. Following the pattern of other options, I tried:
but was not able to get the desired effect. Cursory inspection of https://github.com/mochajs/mocha/blob/master/lib/mocha.js seems to show that this option needs to be added to not only the documentation, but also to the source. |
How exactly do you pass it ? This is my
|
Had the same issue and I think I am not the only one. I just had to move --exit at the end. |
|
Prerequisites
common mistake
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.Description
I have been running specific set of tests for few years now and have been always upgrading to the latest mocha and everything was ok.
With mocha 4 suddenly all tests are passing but it doesn't end as if the --no-exit is automatically added although I never added it.
Steps to Reproduce
Expected behavior:
After all tests end, the process should stop even if there are timeoutes or sockets that prevent the process from existing.
Actual behavior:
Mocha 4 process waits forever like mocha 3 with --no-exit flag
Reproduces how often:
With our tests always. I have 700 tests so it is hard to pinpoint which one casuses the issue or if maybe it is in our codebase.
Versions
mocha 4.0.0 fails. before that everything works good.
The text was updated successfully, but these errors were encountered: