Juggernaut.Coverage.Probe (Juggernaut v0.4.0)

Copy Markdown View Source

The coverage probe (design notes §10.5): every test file run once on the warm pool with the switch in probe mode, to learn which tests run each site.

Each test file is one job, so a hit the recorder owes to the job itself (:job: a setup_all process, an on_exit runner, a process either started) is owed to that file: the job ran nothing else. Files are packed longest first by the tests' recorded durations (plan/3), each to the least loaded worker; a worker runs its files one after another, and the workers run at once.

A probe job must pass: a test that fails, a job that cannot complete (harness error, deadline passed, dead peer) or a worker error stops the probe with an infrastructure error (exit 3), since the coverage of a broken job would be wrong. A job whose run drifted has recycled its worker, which is reported; its hits stand, since they were recorded before the drift was seen.

A job that started on a worker holding state that earlier jobs left and a restore cannot put back (the peer's residue: a memo in a project server's state) may have recorded no hit for the sites that state spared, so its file would never be selected for their mutants. That file is probed again on a fresh worker (recycled first, unless the job's drift already recycled it), and the fresh job's hits stand.

So that the next file seldom has to run twice, each probe job also reports what it leaves (the runner's left: the same check, after the job): a job that leaves such state recycles its worker at once when the worker has more files to probe, so the next file starts on a fresh worker and its first run stands. The check before each job still runs, for state that changes between jobs. A recycle then costs one boot, where it cost a boot and the next file's run; with spares (Juggernaut.Pool.Worker) the boot starts from a parked VM.

Summary

Functions

The files of files packed into n lists, longest first by the sum of their tests' durations (each file to the list with the least total so far, the lower index on a tie; a file of the same cost by name).

Probes files (%{test_file => [id]}, the runnable tests of each file) on workers ([{index, pid}]). Options: :durations (µs by test id, for packing), :seed (0), :timeout_ms (per test, 60 000). Returns each file's hits, with a job's own hits as {:file, file}, its clock and worker.

Types

file_result()

@type file_result() :: %{
  hits: [{pos_integer(), Juggernaut.Coverage.Selection.label()}],
  us: non_neg_integer(),
  tests: non_neg_integer(),
  worker: pos_integer(),
  drift: [String.t()]
}

id()

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

Functions

plan(files, durations, n)

@spec plan(
  %{required(String.t()) => [id()]},
  %{required(id()) => non_neg_integer()},
  pos_integer()
) ::
  [[String.t()]]

The files of files packed into n lists, longest first by the sum of their tests' durations (each file to the list with the least total so far, the lower index on a tie; a file of the same cost by name).

run(workers, files, opts \\ [])

@spec run(
  [{pos_integer(), GenServer.server()}],
  %{required(String.t()) => [id()]},
  keyword()
) ::
  {:ok, %{required(String.t()) => file_result()}}
  | {:error, Juggernaut.Error.t()}

Probes files (%{test_file => [id]}, the runnable tests of each file) on workers ([{index, pid}]). Options: :durations (µs by test id, for packing), :seed (0), :timeout_ms (per test, 60 000). Returns each file's hits, with a job's own hits as {:file, file}, its clock and worker.