The runtime switch that compiled metamutants read (design notes §10.3).
One :persistent_term key, :juggernaut_active, holds a small integer:
0(or unset): every mutant is off and the code behaves as written;- a positive switch: exactly that mutant is on;
-1(probe/0): every mutant is off and each site that runs records a hit.
Every site of a metamutant calls site/2 with its first switch and the number of
mutants it holds, and branches on the answer: 0 runs the original code, i runs the
site's ith mutant. Switches of one site are consecutive, so the call needs no map.
Hits are counted per site (the site's first switch) in a public ETS table created by
arm_hits/0, and handed to Juggernaut.Peer.Recorder.hit/1, which records which test
each hit is owed to. Without the tables a probe hit is dropped, so a metamutant never
fails because recording is off. Updating the key costs well under a millisecond at the
process counts of a large Phoenix app (docs/dependencies/code-loading.md): set it once
per job, never per test.
This module runs inside workers and is never mutated.
Summary
Functions
The active switch (0 when none was set).
Creates the hit table (public, owned by the caller) if it does not exist, and empties it if it does.
Hit counts recorded so far, by site (its first switch). Empty without the table.
The :persistent_term key holding the active switch.
The switch value that turns probe recording on (and every mutant off).
Sets the active switch: 0 for none, a mutant's switch, or probe/0.
Which branch the site whose switches are first..first + count - 1 takes: 0 for the
original code, i (1-based) for its ith mutant. In probe mode the site's hit is
recorded and the original code runs.
Functions
@spec active() :: integer()
The active switch (0 when none was set).
@spec arm_hits() :: :ok
Creates the hit table (public, owned by the caller) if it does not exist, and empties it if it does.
@spec hits() :: %{required(pos_integer()) => pos_integer()}
Hit counts recorded so far, by site (its first switch). Empty without the table.
@spec key() :: atom()
The :persistent_term key holding the active switch.
@spec probe() :: integer()
The switch value that turns probe recording on (and every mutant off).
@spec set(integer()) :: :ok
Sets the active switch: 0 for none, a mutant's switch, or probe/0.
@spec site(pos_integer(), pos_integer()) :: non_neg_integer()
Which branch the site whose switches are first..first + count - 1 takes: 0 for the
original code, i (1-based) for its ith mutant. In probe mode the site's hit is
recorded and the original code runs.