Skip to content

feat(runner): add per-test timeout to abort hanging tests#725

Merged
Chemaclass merged 2 commits into
mainfrom
feat/721-test-timeouts
Jun 16, 2026
Merged

feat(runner): add per-test timeout to abort hanging tests#725
Chemaclass merged 2 commits into
mainfrom
feat/721-test-timeouts

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #721

A test that hangs forever (e.g. a mock left without an implementation that blocks on input) currently hangs the whole run. This adds an opt-in threshold to kill such a test and keep going.

💡 Changes

  • Add --test-timeout <seconds> flag and BASHUNIT_TEST_TIMEOUT env var; a test exceeding the limit fails and the run continues. Disabled by default.
  • Kill the timed-out test's whole process group (no external timeout command needed); works on Bash 3.2+ including default macOS Bash.
  • Fix a latent bug where a non-zero-exit test poisoned the exit code of subsequent tests in the same file.

Add an opt-in `--test-timeout <seconds>` flag and `BASHUNIT_TEST_TIMEOUT`
env var. When set, a test that runs longer than the threshold is killed
and reported as a failure, then the run continues instead of hanging
forever (e.g. a mock left without an implementation that blocks on input).

The test body runs as a backgrounded job in its own process group so a
watchdog can SIGTERM/SIGKILL the whole tree; a hanging test typically
blocks in a child process that signalling the subshell alone cannot reach.
Disabled by default (0), needs no external `timeout` command and works on
Bash 3.2+ (including the default macOS Bash).

Also reset the accumulated per-test exit code before parsing each result,
so a non-zero/timed-out test no longer poisons the next test in the file.

Closes #721
@Chemaclass Chemaclass added the enhancement New feature or request label Jun 16, 2026
@Chemaclass Chemaclass self-assigned this Jun 16, 2026
@Chemaclass Chemaclass merged commit dedb77b into main Jun 16, 2026
31 checks passed
@Chemaclass Chemaclass deleted the feat/721-test-timeouts branch June 16, 2026 06:52
@Chemaclass Chemaclass mentioned this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant