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.

Initial timeout timer starts before tests are run

See original GitHub issue

Run: time ava --timeout 100 bug.js

The above command takes 30 seconds to run, I was expecting ava to fail the testcase after 100 milliseconds.

Another strange thing is that if I instead run: time ava --timeout 1s bug.js …then it exits after 1000ms as expected?!

Contents of bug.js is the following code:

import test from 'ava';

function getTheAnswerToTheMeaningOfLifeTheUniverseAndEverything(callback) {
    setTimeout(() => {
        // Forgetting to invoke callback here
    }, 30000);
}

test.cb('make sure callback is called exactly once', t => {
    t.plan(1);
    getTheAnswerToTheMeaningOfLifeTheUniverseAndEverything(result => {
        t.is(result, 42);
        t.end();
    });
});

Environment

ubuntu 15.10 node v7.7.2 npm 4.5.0 ava 0.19.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
novemberborncommented, May 7, 2017

The problem is that we start the timeout before we launch the test workers. With a 100ms value it might trigger before any tests are ready to run, at which point it kinda gets lost.

I think instead we should track whether we have pending tests, and ensure the timer is running whenever new tests are started, clearing it when tests end. And assume that test workers aren’t stuck in a while loop before they can notify the main process of their tests.

Regardless of the above, I don’t think a value of 100ms is ever realistic given how AVA works. The designed use case of --timeout is to help catch hanging tests, not to limit how long a particular test can take. It’d be better to set the timeout to a few seconds instead.

(Possibly we could consider changing the value to always be in seconds?)

1reaction
novemberborncommented, May 9, 2017

The global timeout documentation makes it sound like the timer starts when the actual testcase starts, and also that the timer is reset whenever a new testcase begins

Yea. There’s definitely a bug: we start the timer before we start collecting tests, and that’s wrong.

In general, I think it’s important that it’s possible to:

  • detect bugs where an expected callback is never invoked

In specific scenarios we can already detect this even without the --timeout option. There are other scenarios where that’s impossible though (say if your test sets up a persistent database connection).

  • detect bugs where an expected callback is invoked two or more times

We currently have no way of failing a test that passed previously, see #1330.

  • detect bugs where a synchronous function accidentally ends up in an infinite loop

Good point, this doesn’t work. Opened #1378.


Let’s continue discussion in the relevant issues. I’ll change the title on this one to deal with the timer starting prematurely.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TCP Timers - GeeksforGeeks
When TCP sends a segment the timer starts and stops when the acknowledgment is received. If the timer expires timeout occurs and the...
Read more >
javascript - Can I see if a timer is still running? - Stack Overflow
There is no need to check for an existing timer, just execute clearTimeout before starting the timer. var timer; //.. var startTimer =...
Read more >
TCP Retransmission Timeout (RTO): Causes & Performance
An RTO occurs when the sender is missing too many acknowledgments and decides to take a time out and stop sending altogether. After...
Read more >
Understanding RTT Impact on TCP Retransmissions
On the initial packet sequence, there is a timer called Retransmission Timeout (RTO) that has an initial value of three seconds.
Read more >
Chapter 21. TCP Timeout and Retransmission
A 2MSL timer measures the time a connection has been in the TIME_WAIT state. We described this state in Section 18.6. In this...
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