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

before handlers timing out looks like the test timing out #8284

Closed
dandv opened this issue Apr 8, 2019 · 7 comments
Closed

before handlers timing out looks like the test timing out #8284

dandv opened this issue Apr 8, 2019 · 7 comments

Comments

@dandv
Copy link
Contributor

dandv commented Apr 8, 2019

🐛 Bug Report

When a beforeAll takes longer than its default timeout, the resulting error message looks hard to distinguish from the test itself timing out. I was debugging a failing test and kept increasing its timeout, when in fact what was causing the failure was the beforeAll function occasionally taking longer than 5 seconds to setup.

To Reproduce

Run the repl. The error with the current version of Jest is verbose but as helpful as it could be:

Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

Expected behavior

Jest should inform the developer that the beforeAll() function timed out.

Link to repl or repo (highly encouraged)

https://repl.it/repls/KnowingGenerousCommas

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
  Binaries:
    Node: 11.13.0 - /usr/bin/node
    Yarn: 1.15.2 - /usr/bin/yarn
    npm: 6.7.0 - /usr/bin/npm
@SimenB
Copy link
Member

SimenB commented Apr 8, 2019

Can you test this with circus? We've changed how failures in hooks like beforeAll affect tests.

See installation instructions in its readme: https://yarnpkg.com/en/package/jest-circus

@dandv
Copy link
Contributor Author

dandv commented May 5, 2019

Seems like the problem persists in circus:

$ npm test --detectOpenHandles --testRunner='jest-circus/runner'

> [email protected] test /home/dandv/prg/jest8284
> ../node_modules/.bin/jest

 FAIL  ./beforeAll-timeout.test.mjs
  ✕ passes (9ms)

  ● passes

    Timeout - Async callback was not invoked within the 1000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 1000ms timeout specified by jest.setTimeout.

      at mapper (node_modules/jest-jasmine2/build/queueRunner.js:25:45)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.343s, estimated 2s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

@SimenB
Copy link
Member

SimenB commented May 5, 2019

To run scripts with npm, you need an extra -- (notice your stack trace says jest-jasmine). Try npm test -- --detectOpenHandles --testRunner='jest-circus/runner'

@dandv
Copy link
Contributor Author

dandv commented May 5, 2019

Ah, good point. Here's the proper invocation:

$ npm test -- --testRunner='jest-circus/runner' ./beforeall-timeout.test.js

> [email protected] test /home/dandv/prg/jest-bugs
> jest "--testRunner=jest-circus/runner" "./beforeall-timeout.test.js"

 FAIL  ./beforeAll-timeout.test.js
  ✕ passes (1ms)

  ● passes

    thrown: "Exceeded timeout of 1000ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      3 | }
      4 | 
    > 5 | beforeAll(async () => {
        | ^
      6 |   // Some operation that usually doesn't take long
      7 |   // but occasionally might time out
      8 |   await sleep(2000);

      at Object.beforeAll (beforeAll-timeout.test.js:5:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.414s, estimated 2s
Ran all test suites matching /.\/beforeall-timeout.test.js/i.
npm ERR! Test failed.  See above for more details.

If beforeAll times out, I expect the entire test to abort, since the setup is undefined (similar to #6695 - beforeAll failing).

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2023
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants