# Timeouts

> Kill a hung test runner and everything it started with --timeout and --total-timeout.

A hung runner can stall CI for hours, and some runners start children in their own session (`swift test` starts
`xctest` that way). trimtest kills the runner **and every descendant**, not just the process it started.

## Per command

```bash
trimtest run --timeout 600
```

```toml
# trimtest.toml
timeout = 600
```

A runner command that runs longer than 600 seconds is killed with everything it started. Its tests count as
failed, are remembered, and run first next time. The flag overrides the config key; `0` or unset means no limit.

## Whole run

```bash
trimtest run --total-timeout 1800
```

```toml
total_timeout = 1800
```

After 1800 seconds in total the command in flight is killed and the remaining commands are **not started**; their
tests count as failed too. Each command gets whichever limit is smaller: the per-command `timeout` or what is left of
the whole-run budget. The flag overrides the config key; `0` or unset means no limit.

## Exit code

A timeout is a test failure, so the run exits `1` and prints which command was killed.

## `record`

`trimtest record --timeout <secs>` (or `timeout` in `trimtest.toml`) applies the same limit to every command that
`record` runs, including the per-test measurements of `--coverage`. A measurement that times out is killed with
everything it started and is not recorded: that test keeps using the static graph (which selects at least as much),
and `record` carries on.
