Runs one job in a booted worker (design notes §10.5): the selected tests, with one switch on, through ExUnit again in the same VM.
A job is a map:
only_test_ids- aMapSetof{module, test_name}. ExUnit silently runs nothing for a list (docs/dependencies/exunit.md), so anything else is refused;switch- the switch on while the tests run (0for none,-1to probe);seed,timeout_ms(per test),max_failures(a positive integer or:infinity);footprint-trueto measure which of the project's functions the tests ran (Juggernaut.Peer.Footprint), for the result cache;order- the modules in the order to name them to ExUnit (modules/2); the selected modules it leaves out follow, sorted;left-trueto report, underleft, what the job leaves that the restore could not put back (the same check asresidue, after the job instead of before), so the host can recycle the worker before the next job rather than run that job again; the check costs a read of the project's servers and tables, so only the probe asks;load_pending-trueto load first the test files the boot left for later (Juggernaut.Peer.Boot.load_pending/0; a boot-lane job's runs after its first).
- with
load_pending, loads the test files the boot left; a file that fails to load givesstatus: :load_error(with themessage), and no test runs; - checks the selection against the boot inventory (every id known);
- configures every ExUnit key the job relies on (settings persist between runs),
with
Juggernaut.Peer.Formatteras the only formatter, sets the switch, runs only the selected tests' modules, in the job's order (modules/2), and sets the switch back to 0. A probe job (switch-1) runs betweenJuggernaut.Peer.Recorder.start_job/2(this process as the job's root, the app's GenServers watched) andfinish_job/0; - checks that ExUnit ran exactly the tests selected (fewer only once
max_failuresstopped it); - puts back the state the job changed (
Juggernaut.Peer.Snapshot.restore/1); - checks health against the boot fingerprint (
Juggernaut.Peer.Health.check/3).
The result has status: :ok, :load_error or :harness_error (with a message;
never a verdict),
the outcome of each test that ran, unfinished (the tests ExUnit started but never
reported finished, in start order: an async module's test still running when
max_failures stopped the run), the counts, what was restored, residue (what
earlier jobs left that a restore cannot put back, found before this job ran:
Juggernaut.Peer.Snapshot.residue/1), lasting (what changed under the lasting
supervisors since boot, before this job ran: Juggernaut.Peer.Health.lasting_residue/2),
left (the residue check again after the job, when it asked; else []),
the drift reasons,
the job's clock in microseconds, memory and atom counts after the job, and hits: a
probe job's {site, label} pairs (Juggernaut.Peer.Recorder), [] for any other, and
footprint: the functions run (or :incomplete) when measured, else nil.
Steps 4 and 5 run whatever steps 1 to 3 gave.
This module runs inside workers and is never mutated.
Summary
Functions
The job's result from what the formatter reported, or {:error, message} when ExUnit
ran a different number of tests than selected (fewer is fine once max_failures
stopped the run).
The modules of the selected tests ids, the list ExUnit.run/1 is given: those
named in order first, in its order, then the others, sorted.
Runs job (see the module doc).
{:ok, ids} when ids is a non-empty MapSet of tests in the inventory tests,
else {:error, message}.
Runs fun with switch on and returns {fun's result, hits}. A probe switch runs it
between Juggernaut.Peer.Recorder.start_job/2 (the calling process as the job's
root, apps' GenServers watched) and finish_job/0, whose hits are returned; any
other switch gives []. The switch is set back to 0, and a probe's debug functions
removed, even when fun raises, throws or exits.
Types
@type job() :: %{ :only_test_ids => MapSet.t({module(), atom()}), optional(:switch) => integer(), optional(:seed) => non_neg_integer(), optional(:timeout_ms) => pos_integer(), optional(:max_failures) => pos_integer() | :infinity, optional(:footprint) => boolean(), optional(:order) => [module()], optional(:load_pending) => boolean() }
Functions
@spec counted(non_neg_integer(), [Juggernaut.Peer.Formatter.outcome()], boolean()) :: map() | {:error, String.t()}
The job's result from what the formatter reported, or {:error, message} when ExUnit
ran a different number of tests than selected (fewer is fine once max_failures
stopped the run).
@spec modules(Enumerable.t({module(), atom()}), [module()]) :: [module()]
The modules of the selected tests ids, the list ExUnit.run/1 is given: those
named in order first, in its order, then the others, sorted.
ExUnit runs sync modules one at a time in exactly that order, and starts async ones in
it, so the order must not depend on how many tests are selected: a MapSet of up to 32
elements iterates in sorted order, a larger one in hash order. Given the same order,
the modules of fewer of a run's tests (a kill's narrowed control,
Juggernaut.Runner.control_runs/1) run in the order they ran in the whole run. The
host gives the job's order (Juggernaut.Runner.module_order/1: the killer's and the
hitting tests' modules first), so a kill comes after fewer modules (D2).
Runs job (see the module doc).
{:ok, ids} when ids is a non-empty MapSet of tests in the inventory tests,
else {:error, message}.
@spec switched(integer(), [atom()], (-> result)) :: {result, [{pos_integer(), term()}]} when result: term()
Runs fun with switch on and returns {fun's result, hits}. A probe switch runs it
between Juggernaut.Peer.Recorder.start_job/2 (the calling process as the job's
root, apps' GenServers watched) and finish_job/0, whose hits are returned; any
other switch gives []. The switch is set back to 0, and a probe's debug functions
removed, even when fun raises, throws or exits.