Skip to content

feat: ensure teardown always runs (even when setup fails or on SIGINT/SIGTERM)#7

Merged
andreasjansson merged 59 commits intomainfrom
teardown-always-runs
Feb 2, 2026
Merged

feat: ensure teardown always runs (even when setup fails or on SIGINT/SIGTERM)#7
andreasjansson merged 59 commits intomainfrom
teardown-always-runs

Conversation

@andreasjansson
Copy link
Owner

Summary

This PR ensures that _teardown.txt always runs, regardless of:

  • Whether tests passed or failed
  • Whether setup failed (main tests are skipped but teardown still runs)
  • Whether the process was interrupted by SIGINT (Ctrl-C) or SIGTERM

Changes

Core Changes

  • runner.rs: Refactored run_suite to not return early on setup failure - instead it skips main tests but continues to teardown
  • runner.rs: Added ignore_interruption parameter to run_corpus_file so teardown can run even when the interrupted flag is set
  • main.rs: Added signal handler using ctrlc crate (with termination feature) to catch SIGINT, SIGTERM, and SIGHUP
  • runner.rs: Added INTERRUPTED atomic flag and checks between tests to enable graceful shutdown

New Tests

  • test/teardown_always/ - comprehensive tests for teardown-always-runs behavior
    • Unix tests using /tmp marker files
    • Windows tests using %TEMP% marker files
    • Verifies setup runs, teardown runs, and main tests are skipped when setup fails

Documentation

  • Updated README.md to clarify teardown behavior

Limitations

  • SIGKILL: Cannot be caught (kernel-level immediate termination)
  • Signal handling in subshells: When cctr runs inside bash -c or as a background process, signal handling may not work reliably. Works correctly when cctr runs directly.

Testing

All existing tests pass plus 6 new Unix tests and 5 new Windows tests (platform-skipped appropriately).

@andreasjansson andreasjansson merged commit 4a36970 into main Feb 2, 2026
6 checks passed
@andreasjansson andreasjansson deleted the teardown-always-runs branch February 2, 2026 23:14
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.

1 participant