# `Juggernaut.Pool.Baseline`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/pool/baseline.ex#L1)

The sharded baseline (design notes §10.5, plan I19): the needed tests, every mutant
off, split across the workers so that every worker runs at least one shard. It proves
each worker (its partition, its database, its loaded tests) before any mutant runs on
it, and records each test's duration for scheduling.

Shards are packed longest first (`shards/3`) by the durations given (an unknown
duration counts as 0). When there are fewer tests than workers, tests are repeated so
that no worker is left unproven. Each shard runs with `max_failures: :infinity`.

A test that fails is run once more on the same worker. Still failing: the baseline
fails; passing the second time: the baseline is flaky. Both are infrastructure errors
(exit 3) naming the tests and workers, because a mutant scored against a failing or
flaky test would be a false kill. A harness error, a deadline passed or a dead peer,
in the shard or in the re-run of its failed tests, is an infrastructure error too.

A shard whose run drifts recycles its worker, so the shard runs once more, on the
fresh peer: the run that proves the worker, and whose failed tests are re-run on that
same peer, is one that left the worker as it found it. Drift on that second run too
fails the baseline (exit 3): the suite leaves state behind that a restore cannot put
back, so no job on the worker could be trusted.

# `id`

```elixir
@type id() :: {module(), atom()}
```

# `run`

```elixir
@spec run([{pos_integer(), GenServer.server()}], [id()], keyword()) ::
  {:ok, %{durations: %{required(id()) =&gt; non_neg_integer()}, shards: [map()]}}
  | {:error, Juggernaut.Error.t()}
```

Runs `tests` on the `workers` (`[{index, pid}]`). Options: `:durations` (µs by test
id, for packing), `:seed` (0), `:timeout_ms` (per test, 60 000), `:deadline_ms` (per
shard, default the sum of the per-test timeouts). Returns the measured duration of each
test (µs) and each shard's worker, size, clock and counts, with `drift` the drift of
a first run that recycled the worker (`[]` when none did).

# `shards`

```elixir
@spec shards([id()], %{required(id()) =&gt; non_neg_integer()}, pos_integer()) :: [
  [id()]
]
```

`tests` packed into `n` shards, longest first by `durations` (each test to the shard
with the least total so far, the lower index on a tie). Every shard gets at least one
test while there are tests: with fewer tests than shards, tests are repeated in order.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
