Giter VIP home page Giter VIP logo

Comments (8)

jlongo-encora avatar jlongo-encora commented on May 25, 2024 1

It seems like an issue with the Node version I was using. See this:

With Node 16.14:

jlongo@x:~/git/test$ nvm use 16.14
Now using node v16.14.2 (npm v8.5.0)
jlongo@x:~/git/test$ ./node_modules/.bin/jest --detectOpenHandles
 PASS  ./test.js
  GET `/` route
    ✓ test (73 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.325 s, estimated 1 s
Ran all test suites.

With Node 16.3.2:

jlongo@x:~/git/test$ nvm use 16.13.2
Now using node v16.13.2 (npm v8.1.2)
jlongo@x:~/git/test$ ./node_modules/.bin/jest --detectOpenHandles
 PASS  ./test.js
  GET `/` route
    ✓ test (71 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.331 s, estimated 1 s
Ran all test suites.

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

  ●  fastify-request-context

      34 |
      35 |   it('test', (done) => {
    > 36 |     fastify.inject({
         |             ^
      37 |         method: 'GET',
      38 |         url: '/'
      39 |       }, (err, response) => {

      at Object.ready (node_modules/fastify/fastify.js:481:13)
      at Object.inject (node_modules/fastify/fastify.js:459:12)
      at Object.<anonymous> (test.js:36:13)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

Thanks!

from fastify-request-context.

jsumners avatar jsumners commented on May 25, 2024

Does this happen without Jest?

from fastify-request-context.

mcollina avatar mcollina commented on May 25, 2024

This is a limitation of Jest.

from fastify-request-context.

jlongo-encora avatar jlongo-encora commented on May 25, 2024

This is not a limitation of Jest. Jest has a nice feature that checks if we are not closing properly the resources at the end of the tests. Without 'fastify-request-context', there is no issue. Essentially, Jest is telling us there are pending resources with 'fastify-request-context', even after we call fastify.close().

I'm not sure if other libraries have this check.

from fastify-request-context.

mcollina avatar mcollina commented on May 25, 2024

That's how the request context work. There is likely something that has becomes part of your promise chain. It's likely safe.

from fastify-request-context.

climba03003 avatar climba03003 commented on May 25, 2024

This library actually tested with jest. If it has problem with open handles, the test should be failed.
I have follow your repro and it is actually no error on my end.

$ node -v
v16.14.0

$ jest  --detectOpenHandles
 PASS  ./test.js
  GET `/` route
    ✓ test (698 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.815 s
Ran all test suites.
Done in 6.83s.

Your error actually pointing to fastify.js#L481 which means something is not handled properly inside the onReady hook when process exit.
Do you have any onReady hook registered for the instance?

from fastify-request-context.

jlongo-encora avatar jlongo-encora commented on May 25, 2024

Note that I enabled the option "--detectOpenHandles". The test won't fail if there are open handles, but it's a warning the code is not closing all resources properly.

@climba03003 no, the scenario I sent just contains those files.

Is there a way I can force "fastify-request-context" to close?

from fastify-request-context.

climba03003 avatar climba03003 commented on May 25, 2024

Note that I enabled the option "--detectOpenHandles". The test won't fail if there are open handles, but it's a warning the code is not closing all resources properly.

@climba03003 no, the scenario I sent just contains those files.

Is there a way I can force "fastify-request-context" to close?

You can see my command is running jest --detectOpenHandles and it works very well. The time is long because I am running benchmark job in background.
image

from fastify-request-context.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.