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

Testing with Jest - detected open handle when using TypeOrmHealthIndicator #1466

Closed
2 of 4 tasks
robertozmc opened this issue Oct 5, 2021 · 5 comments · Fixed by #1576
Closed
2 of 4 tasks

Testing with Jest - detected open handle when using TypeOrmHealthIndicator #1466

robertozmc opened this issue Oct 5, 2021 · 5 comments · Fixed by #1576

Comments

@robertozmc
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When running jest tests a timeout open handle is reported:

PASS test/endpoint/health/health.test.ts (11.348 s)
PASS test/endpoint/health/ready.test.ts
PASS test/endpoint/health/live.test.ts
PASS test/integration/controllers/health.controller.test.ts

Test Suites: 4 passed, 4 total
Tests:       4 passed, 4 total
Snapshots:   0 total
Time:        15.259 s
Ran all test suites.

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

  ●  Timeout
      31 |   @HealthCheck()
      32 |   check(): Promise<HealthCheckResult> {
    > 33 |     return this.health.check([() => this.db.pingCheck('database')]);
         |                                             ^
      34 |   }
      35 |
      36 |   /**

      at node_modules/@nestjs/terminus/dist/utils/promise-timeout.js:26:18
      at promiseTimeout (node_modules/@nestjs/terminus/dist/utils/promise-timeout.js:25:19)
      at TypeOrmHealthIndicator.<anonymous> (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:103:53)
      at node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:17:71
      at Object.<anonymous>.__awaiter (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:13:12)
      at TypeOrmHealthIndicator.pingDb (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:87:16)
      at TypeOrmHealthIndicator.<anonymous> (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:127:28)
      at node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:17:71
      at Object.<anonymous>.__awaiter (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:13:12)
      at TypeOrmHealthIndicator.pingCheck (node_modules/@nestjs/terminus/dist/health-indicator/database/typeorm.health.js:116:16)
      at src/controllers/health.controller.ts:33:45
      at HealthCheckExecutor.<anonymous> (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:66:42)
      at node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:14:71
      at Object.<anonymous>.__awaiter (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:10:12)
      at HealthCheckExecutor.executeHealthIndicators (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:61:16)
      at HealthCheckExecutor.<anonymous> (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:50:52)
      at node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:14:71
      at Object.<anonymous>.__awaiter (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:10:12)
      at HealthCheckExecutor.execute (node_modules/@nestjs/terminus/dist/health-check/health-check-executor.service.js:49:16)
      at HealthCheckService.<anonymous> (node_modules/@nestjs/terminus/dist/health-check/health-check.service.js:58:59)
      at node_modules/@nestjs/terminus/dist/health-check/health-check.service.js:17:71
      at Object.<anonymous>.__awaiter (node_modules/@nestjs/terminus/dist/health-check/health-check.service.js:13:12)
      at HealthCheckService.check (node_modules/@nestjs/terminus/dist/health-check/health-check.service.js:57:16)
      at HealthController.check (src/controllers/health.controller.ts:33:24)
      at Object.<anonymous> (test/integration/controllers/health.controller.test.ts:25:41)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:387:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:408:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:261:3)

Minimum reproduction code

https://github.com/robertozmc/nestjs-terminus-issue

Steps to reproduce

Run script ./test.sh

Expected behavior

Pass all tests without open handle report

Package version

8.0.1

NestJS version

8.0.1

Node.js version

16

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@michaeldfallen
Copy link

Any update on this issue? It is preventing the testing of health controllers which we would like to avoid.

@BrunnerLivio
Copy link
Member

Sorry for the delay!

Thanks a lot for the minimal reproduction @robertozmc, that helped tremendously while debugging this. I think I found the issue. I'll release a beta release ASAP, would appreciate if you could then quickly try it :)

@BrunnerLivio
Copy link
Member

Just released the beta 8.0.2. Check it with npm install --save @nestjs/terminus@beta

I also checked the minimal reproduction and it works like a charm.
Can you quickly check whether this is the case for your applications as well? @michaeldfallen @robertozmc

@BrunnerLivio
Copy link
Member

Released with 8.0.3 🎉

@robertozmc
Copy link
Author

@BrunnerLivio sorry for being late to reply, other stuff got in the way.

I just checked your changes and the issue is gone.
Thank you so much, appreciating your work. 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants