Skip to content
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

[Server] Jest open handles #100

Closed
devYaoYH opened this issue Jun 19, 2020 · 4 comments
Closed

[Server] Jest open handles #100

devYaoYH opened this issue Jun 19, 2020 · 4 comments
Labels
Backend Stuff to do with express in `/server` bug Something isn't working Testing Writing Test/Framework to Test

Comments

@devYaoYH
Copy link
Collaborator

yarn test - Success
yarn test --detectOpenHandles - Last test fails
Need to investigate further

@devYaoYH devYaoYH added bug Something isn't working Backend Stuff to do with express in `/server` Testing Writing Test/Framework to Test labels Jun 19, 2020
@devYaoYH
Copy link
Collaborator Author

Side effect of detected open handles also preventing jest from exiting after tests are complete

  • Delays completion of server testing script by ~1min

@devYaoYH
Copy link
Collaborator Author

Side-effect of #105, resolving that issue would resolve this one as well.

@redhoteggplant
Copy link
Collaborator

Just adding a note that open handles are separate and seem to be an issue in supertest, and current workarounds are just using setTimeout() or --forceExit

@redhoteggplant redhoteggplant changed the title Indeterminancy in server tests [Server] Jest open handles Jun 24, 2020
@redhoteggplant
Copy link
Collaborator

redhoteggplant commented Jun 24, 2020

(Just adding more information in case we come back to this issue)

Running jest test gives the following warning:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

Running jest --detectOpenHandles as suggested detects open handles from app.listen() or request(app).get(), with an example output below:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TCPSERVERWRAP

      38 | app.use(compression());
      39 | 
    > 40 | server = app.listen(PORT, function () {
         |              ^
      41 |   console.log(config.ENV);
      42 | });
      43 | 

Attempts:

  1. server.close() at the end of all tests
  2. server.close() in afterAll()
  3. server.close(done)
  4. Remove app.listen() and server.close() in test env, similar to here
  5. setting up an agent that uses the allocated port instead of a random port, or using end() to force supertest to close the automatic bound connection, as suggested in the supertest issue #520
  6. Add Promise.all(firebase.apps().map(app => app.delete())) to clean up Firebase apps after tests, as the docs note that that initialized apps with active listeners prevent JavaScript from exiting
  7. Hacky ways: run jest with --forceExit, or setTimeout() after all tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Stuff to do with express in `/server` bug Something isn't working Testing Writing Test/Framework to Test
Projects
None yet
Development

No branches or pull requests

2 participants