Open handles when starting and stopping an http server in a test.
See original GitHub issue🐛 Bug Report
Starting an http server results in an open handle despite closing the server down after tests ran.
To Reproduce
Steps to reproduce the behavior:
Create the following file named demo.test.js
:
const http = require('http');
describe('demo', () => {
let server;
beforeAll(() => {
server = http.createServer((req, res) => {
res.write('ok');
res.end();
});
server.listen();
});
afterAll(async() => {
await server.close();
});
test('my test', async () => {
});
});
Running with jest produces the following output
$ npx jest --detectOpenHandles .
PASS ./demo.test.js
demo
✓ my test (2ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.759s
Ran all test suites matching /./i.
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPSERVERWRAP
10 | res.end();
11 | });
> 12 | server.listen();
| ^
13 | });
14 |
15 | afterAll(() => {
at Object.listen (demo.test.js:12:16)
Expected behavior
No open handles should be left.
Run npx envinfo --preset jest
Paste the results here:
$ npx envinfo --preset jest
npx: installed 1 in 1.938s
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: x64 Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz
Binaries:
Node: 10.8.0 - ~/.nvm/versions/node/v10.8.0/bin/node
npm: 6.2.0 - ~/.nvm/versions/node/v10.8.0/bin/npm
npmPackages:
jest: ^23.5.0 => 23.5.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
go - How to stop http.ListenAndServe() - Stack Overflow
The problem is that in my application the HTTP server is only one component and it is required to stop and start at...
Read more >Graceful shutdown in Go http server | by Sam Wang - Medium
When backend developers writing http servers, the most usual question is: how am I being able to terminate all the running processes and ......
Read more >HTTP server - Learn Go with tests - GitBook
This will start a web server listening on a port, creating a goroutine for every request and running it against a Handler ....
Read more >http.Server.Shutdown() crashing? - Google Groups
This is the output after visiting http://localhost:8080/stop on my browser. 2017/07/09 13:58:40 Server starting up. ... Println("test - before shutdown").
Read more >How do you make sure your website works properly?
stopped working, or the web server itself has a configuration problem. Usually it's best to resort to your hosting provider's support team. 503: ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to follow this up, should anybody read this because they’re testing with supertest and express. The following leaves no open handles.
That’s because you don’t wait for it to close down. The http API is callback based, not promise.
This successfully closes down without a warning from
detectOpenHandles
: