This repository has been archived by the owner on May 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: We can now upgrade to mocha@5 🌮
## 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 ```
- Loading branch information