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

Timeout does not function if test is writing to the console #3373

Open
mdouglass opened this issue Apr 3, 2025 · 1 comment · May be fixed by #3374
Open

Timeout does not function if test is writing to the console #3373

mdouglass opened this issue Apr 3, 2025 · 1 comment · May be fixed by #3374
Labels
bug current functionality does not work as desired scope:internals

Comments

@mdouglass
Copy link

Please provide details about:

  • What you're trying to do
    I have a test which is writing debug logs to the console but not making any asserts. The timeout on that test is triggering that the test failed, but not actually stopping the test run so ava never exits.

Timeouts can also be set individually for each test. These timeouts are reset each time an assertion is made. The test fails if it takes more than ms for an assertion to be made or the test to complete.

  • What happened
$ npm test will-not-stop.js

> test
> ava will-not-stop.js


0s
1s
2s
3s
4s
  ✘ [fail]: will not stop stop after 5s
5s
6s
7s
...
62s
^C  
  ✘ Exiting due to SIGINT

  Failed to exit when running will-not-stop.js

  ─

  will not stop

  Error: stop after 5s

  Error: stop after 5s
      at Timeout.<anonymous> (file:///Users/matthew/spikes/repro-ava-timeout/node_modules/ava/lib/test.js:439:24)
      at listOnTimeout (node:internal/timers:594:17)
      at process.processTimers (node:internal/timers:529:7)

  ─

  1 test failed
  • What you expected to happen
    I expected the test to exit after it was marked as having failed, as in this example:
$ npm test will-stop.js

> test
> ava will-stop.js


  ✘ [fail]: will stop stop after 5s
  
  ✘ Timed out while running tests

  Failed to exit when running will-stop.js

  ─

  will stop

  Error: stop after 5s

  Error: stop after 5s
      at Timeout.<anonymous> (file:///Users/matthew/spikes/repro-ava-timeout/node_modules/ava/lib/test.js:439:24)
      at listOnTimeout (node:internal/timers:594:17)
      at process.processTimers (node:internal/timers:529:7)

  ─

  1 test failed

Sample Code:

  1. Run npm init ava to create a skeleton project (done on 04/03/2025, ava v6.2.0)
  2. Add will-not-stop.js
import test from "ava";

test("will not stop", async (t) => {
  t.timeout(5_000, "stop after 5s");
  for (let i = 0; ; ++i) {
    console.log(`${i}s`);
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
});
  1. Add will-stop.js (same as will-not-stop but with the write call commented out)
import test from "ava";

test("will not stop", async (t) => {
  t.timeout(5_000, "stop after 5s");
  for (let i = 0; ; ++i) {
    // console.log(`${i}s`);
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
});
@novemberborn
Copy link
Member

For future readers, the issue here is that AVA believes the test worker is still active, but only because it's writing to stdout. It therefore doesn't exit. The lack of exiting is because the timeout itself is keeping the worker alive, but AVA should have detected the worker not exiting.

More in #3374.

@novemberborn novemberborn added bug current functionality does not work as desired scope:internals and removed needs triage labels Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired scope:internals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants