The coverage recorder of a worker (design notes §10.5): which sites run, and on behalf of which test.
A metamutant site in probe mode (Juggernaut.Peer.Switch.probe/0) calls hit/1 with
its first switch, in whatever process runs it. The recorder stores {site, label} once
in an ETS set, where the label says what the hit is owed to:
:boot- the app was starting (or the test helpers loading):arm_boot/0up totake_boot/0. Such a site goes to the boot lane (§10.8);{:test, {module, name}}- a test, found from the hitting process;:job- a process of the running job that no test owns: asetup_allprocess, anon_exitrunner, or a process one of them started. The probe runs one test file per job, so the controller reads:jobas that whole file;{:none, {kind, who}}- no test and not the job: a process of the app serving a cast, a timer or another message, or a call from a process no test owns.kindis:call,:cast,:infoor:process,whonames the process.
Labels are resolved from process provenance, never from time windows:
- the process's own label: ExUnit labels each test process
{module, name}(Process.set_label/1), and a label counts only whenmoduleis a test module; - the processes it acts for, walked in order: the caller of the GenServer call it is
serving (
$juggernaut_from, set bydebug/3, the:sysdebug functionstart_job/1installs on the app's GenServers), its$callers(set byTask), its$ancestors(set byproc_lib) and its spawning parent (Process.info/2:parent). Each pid reached is resolved through its own$callers,$ancestorsand parent, never through its served caller: a server's$juggernaut_fromnames the caller it serves now, not the one it served when it started a helper, so following it from another process would owe a hit to whichever test called last. A process related to a server only by spawning (a helper, aTaskthe server starts) is therefore unattributed unless its own$callersreach a test. Reaching the job's own process (the one runningExUnit.run/1) gives:job; - otherwise
{:none, reason}.
A dead pid ends its branch of the walk (its links cannot be read), so a process that
outlives the test that started it is unattributed: the conservative answer, since its
site then runs the whole suite. The walk's answer is kept in the process dictionary
until the process's $callers, served caller or message kind changes, or the process
that gave the label dies; a test process's own label is read on every hit.
This module runs inside workers and is never mutated. Nothing here raises into a metamutant: a failed record is dropped.
Summary
Functions
The processes of app's supervision tree that are not supervisors (named or
anonymous children), found from its application master.
Creates the hit table, owned by a process of its own that lives as long as the VM (a
:peer call runs in a process that exits when the call returns), or empties it.
Records every hit as :boot from now until take_boot/0.
The :sys debug function installed on the app's GenServers during a probe job. It runs
in the server's process before each incoming message is handled and records, in that
process's dictionary, the caller of a call ($juggernaut_from) and the kind of
message ($juggernaut_in): :call, :cast or :info. Other events are left alone.
Stops recording and removes the hit table (for tests).
Ends the probe job: removes the debug functions and returns the job's {site, label}
pairs, sorted; the table is emptied.
Records a hit on site with the label of the calling process (see the module doc).
The label of the calling process in a job run by root.
The processes another process pid acts for, as the walk follows them: its
$callers, $ancestors and parent. Its served caller ($juggernaut_from) is left
out: only the server's own process follows it, while it serves that call.
A short name for pid: its registered name, else its initial call.
Starts a probe job run by root (the process that calls ExUnit.run/1): empties the
table and installs debug/3 on every GenServer of apps' supervision trees.
Stops boot recording: the sites hit since arm_boot/0, sorted; the table is emptied.
{module, name} when label is an ExUnit test's label, else nil.
Installs debug/3 on each of pids that is an idle gen_server or gen_statem, until
finish_job/0; returns those it was installed on.
Types
Functions
The processes of app's supervision tree that are not supervisors (named or
anonymous children), found from its application master.
@spec arm() :: :ok
Creates the hit table, owned by a process of its own that lives as long as the VM (a
:peer call runs in a process that exits when the call returns), or empties it.
@spec arm_boot() :: :ok
Records every hit as :boot from now until take_boot/0.
The :sys debug function installed on the app's GenServers during a probe job. It runs
in the server's process before each incoming message is handled and records, in that
process's dictionary, the caller of a call ($juggernaut_from) and the kind of
message ($juggernaut_in): :call, :cast or :info. Other events are left alone.
@spec disarm() :: :ok
Stops recording and removes the hit table (for tests).
@spec finish_job() :: [{pos_integer(), label()}]
Ends the probe job: removes the debug functions and returns the job's {site, label}
pairs, sorted; the table is emptied.
@spec hit(pos_integer()) :: :ok
Records a hit on site with the label of the calling process (see the module doc).
The label of the calling process in a job run by root.
The processes another process pid acts for, as the walk follows them: its
$callers, $ancestors and parent. Its served caller ($juggernaut_from) is left
out: only the server's own process follows it, while it serves that call.
A short name for pid: its registered name, else its initial call.
Starts a probe job run by root (the process that calls ExUnit.run/1): empties the
table and installs debug/3 on every GenServer of apps' supervision trees.
@spec take_boot() :: [pos_integer()]
Stops boot recording: the sites hit since arm_boot/0, sorted; the table is emptied.
{module, name} when label is an ExUnit test's label, else nil.
Installs debug/3 on each of pids that is an idle gen_server or gen_statem, until
finish_job/0; returns those it was installed on.