question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synchronous tests don't time out

See original GitHub issue

🐛 Bug Report

jest.setTimeout(timeout) does not time out for synchronous tests.

To Reproduce

run

  it('times out', () => {
    const startTime = new Date().getTime();
    while (new Date().getTime() - startTime < 10000) {
      // wait
    }
  });

Expected behavior

The test times out.

Link to repl or repo

https://repl.it/@gitlab_winnie/jestsetTimeouttimeout-for-synchronous-tests

Run npx envinfo --preset jest

  Binaries:
    Node: 9.0.0 - ~/.nvm/versions/node/v9.0.0/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 5.8.0 - ~/.nvm/versions/node/v9.0.0/bin/npm
  npmPackages:
    jest: ^23.5.0 => 23.5.0

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Mar 5, 2019

but I’m still not sure if enabling it by default would be useful for most users

@rubennorte Maybe we can create a separate follow-up issue to discuss whether this should become the default behavior? Then people can throw their 👍s and 👎s at it after trying it out. 😃

Personally I wouldn’t mind if it is not the default but having it at all would be a big help.

2reactions
slombardocommented, Mar 23, 2022

I am able repro this. I also was able to narrow it down (in my case) to nested long running for loops:

describe("timeout tests", () => {
    test('Times out properly', (done) => {
        setTimeout(done, 10000);
    }, 2000);

    test('Times out properly', (done) => {
        for (let i = 0; i < 937351770; i++) {
        }
    }, 2000);

    test('Does not time out at all, just spins', (done) => {
        for (let i = 0; i < 937351770; i++) {
            for (let j = 0; j < 937351770; j++) {

            }
        }
    }, 2000);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing With Synchronization Issues in Tests | Detox
We are waiting too much - The test will appear to hang and fail with timeout. This happens because Detox thinks an asynchronous...
Read more >
Stopping tests on timeout - TestArchitect Docs
A test case timeout occurs during runtime when run duration, accumulated from the beginning of a test case, exceeds a specific timeout. Run...
Read more >
Message "Async callback was not invoked within the 5000 ms ...
Sometimes, when I run the tests, everything works as expectedly. Other times, I get an error: Timeout - Async callback was not invoked...
Read more >
How Does Silk Test Workbench Synchronize Tests?
If Silk Test Workbench cannot immediately find an object, Silk Test Workbench will retry to find the object until the object resolve timeout...
Read more >
Handle pauses & timeouts effectively - BDD framework for NET
Stan Desyatnikov proposed a way to rephrase the waiting scenarios. “Don't reflect delays (of the application under testing) in steps of scenarios… Wait...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found