Initial timeout timer starts before tests are run
See original GitHub issueRun: 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?)
Yea. There’s definitely a bug: we start the timer before we start collecting tests, and that’s wrong.
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).We currently have no way of failing a test that passed previously, see #1330.
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.