Skip to content

feat: add per-file deadline with --file-timeout - #69

Open
gauthier-xo wants to merge 1 commit into
ExodusOSS:mainfrom
gauthier-xo:feat/per-file-deadline
Open

gauthier-xo wants to merge 1 commit into
ExodusOSS:mainfrom
gauthier-xo:feat/per-file-deadline

Conversation

@gauthier-xo

Copy link
Copy Markdown

Summary

On node:test, a hung test file now gets killed at a deadline. The file is listed under Failed test suites: and the run moves on. Before this change, one stuck file stalled the whole run until the CI job timeout, and the log never said which file hung.

New flag --file-timeout <ms>. The default is 50x testTimeout, the rule barebone engines already use.

 node --test --import loader/file-timeout.js files...
   test child (NODE_TEST_CONTEXT=child*)
+    watchdog Worker (own event loop, unref'd)
+      after ms: writeSync(2, "File timeout of <ms>ms reached, killing <file>")
+                process.kill(process.pid, 'SIGKILL')
   bin/inband.js
     for each inband file
+      restartFileTimeout(file)
       describe(...import(file))

 pure engines (barebone, node:pure, browsers, ...)
-  timeout = (testTimeout || jest testTimeout || 5000) * 50
+  timeout = options.fileTimeout   # same default, overridable
Engine Behavior
node:test, electron-as-node:test watchdog worker per test child
pure / bundle / barebone / browsers --file-timeout replaces the hardcoded 50x
deno:test, bun:test --file-timeout exits with <engine> does not support --file-timeout
  • Validation: the value must be an integer greater than the effective testTimeout. It's checked after jest config loads, so testTimeout from config counts.
  • The watchdog lives in a worker thread, so a main thread stuck in for (;;) {} can't stop it.
  • It is armed only in test children (NODE_TEST_CONTEXT=child*), not in the node --test parent.
  • It is not armed under --inspect*, so debugger sessions aren't killed.

Evidence

Fixtures are in tests/integration/file-timeout/. The run below uses --jest --testTimeout 900 --file-timeout 1000.

  • Before: blocking.js and toplevel-await.js hang forever. The run never finishes.
  • After:
    # tests/integration/file-timeout/blocking.js
    ‼ FATAL File timeout of 1000ms reached, killing tests/integration/file-timeout/blocking.js
    ✖ FAIL tests/integration/file-timeout/blocking.js
    # tests/integration/file-timeout/passing.js
    ✔ PASS passes
    # tests/integration/file-timeout/toplevel-await.js
    ‼ FATAL File timeout of 1000ms reached, killing tests/integration/file-timeout/toplevel-await.js
    ✖ FAIL tests/integration/file-timeout/toplevel-await.js
    Failed test suites:
      tests/integration/file-timeout/blocking.js
      tests/integration/file-timeout/toplevel-await.js
    
    Two inband files sleep 700ms each. Both pass, so each gets its own 1000ms budget.

tests/cli/file-timeout.test.js has 8 tests. They spawn bin/index.js and check:

  • event-loop block and top-level-await hang are killed and listed as failed
  • later files still run; inband files don't share one budget
  • --file-timeout overrides the deadline on node:pure (pure path, same as barebone)
  • 0, -1, 1.5, abc, and a value not above testTimeout all exit 1 with an error
  • --engine deno:test --file-timeout exits 1
  • CI=1 pnpm test:all passes on Node 22.22 (148/144/147/70 suites across modes)
  • new test passes on Node 20.20
  • electron-as-node:test is covered only by CI

tests/cli/ is added to the test:_bundle ignore list because bundled engines can't spawn processes.

Merge Danger

Door: two-way

Blast Radius: CI runs

  • Any node:test file that legitimately runs longer than 50x testTimeout (250s by default) now fails. Before, it passed. Raise the limit with --file-timeout.
  • When an inband file times out, the whole inband process is killed. Inband files after it in that process don't run.
  • Output from a killed file can land under a neighbouring file's header. That's existing attribution in reporter.js for test:stderr. The FATAL line always names the right file.

Closes #65

A hanging test file on node:test was never stopped, stalling the run
until the CI job timeout without naming the file. A watchdog worker
thread in each test child kills the process at the deadline, so it
works even when the file blocks the event loop. Inband files re-arm
the watchdog per file.

The same option replaces the hardcoded 50x testTimeout on pure
engines and keeps it as the default.

Closes ExodusOSS#65

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-file deadline on the node:test engine

1 participant