Juggernaut.Cache.Shard (Juggernaut v0.4.0)

Copy Markdown View Source

The result cache on disk (design notes §7.3): one compact JSON file per mutated source file, under a directory named for the cache's globals.

cache/results/g-<16 hex of the globals' sha>/<16 hex of the file's sha>.json

A shard holds the entries of the mutants of one source file, with what entries share written once and referred to by index:

  • sources - [file, content sha, [[function key, hash], ...]]: each footprint file at one content, with the functions any entry recorded in it. An entry's footprint is [[source index, [function index, ...]], ...];
  • test_files - [file, hash]: an entry's tests is [index, ...];
  • tests - [id, module, name, file, line]: a result's tests (and killed_by) is [[index, duration_ms, outcome], ...].

Reading a shard gives back exactly the entries written (encode/3, read/2). The single-file cache this replaces held each entry's footprint hashes, file shas and test references in full, once per entry, and was rewritten whole on every run (157 MB on a large Phoenix app); a shard is rewritten only when its file's entries change.

Summary

Functions

The directory of the shards written under globals, inside the cache path.

The JSON of the shard of source file's entries (by mutant key) under globals.

The shard of source file in dir.

The shard paths in dir of files, or every shard there with :all.

Removes, from the cache path, every shard directory but keep, and the format 1 file (path with .json): what other globals wrote can never be read again.

The entries of the shard at path (by mutant key), or none when it is missing, unreadable, of another format or written under other globals.

Functions

dir(path, globals)

@spec dir(Path.t(), String.t()) :: Path.t()

The directory of the shards written under globals, inside the cache path.

encode(globals, file, entries)

@spec encode(String.t(), String.t(), %{required(String.t()) => map()}) :: iodata()

The JSON of the shard of source file's entries (by mutant key) under globals.

path(dir, file)

@spec path(Path.t(), String.t()) :: Path.t()

The shard of source file in dir.

paths(dir, files)

@spec paths(Path.t(), [String.t()] | :all) :: [Path.t()]

The shard paths in dir of files, or every shard there with :all.

prune(path, keep)

@spec prune(Path.t(), Path.t()) :: :ok

Removes, from the cache path, every shard directory but keep, and the format 1 file (path with .json): what other globals wrote can never be read again.

read(path, globals)

@spec read(Path.t(), String.t()) :: %{required(String.t()) => map()}

The entries of the shard at path (by mutant key), or none when it is missing, unreadable, of another format or written under other globals.