runner

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MeasureBaseline

func MeasureBaseline(ctx context.Context, projectDir string, packages []string, tags string, testFlags []string) (time.Duration, error)

MeasureBaseline runs the test suite once to determine baseline duration. testFlags are the user's --test-flags, forwarded here too so the baseline measures the same work the per-mutant runs will do — otherwise a `-short`-ed mutation run would be sized against a full-cost baseline.

They land *after* the package arguments. `go test` keeps parsing its own flags past one it does not recognize, but that first unrecognized flag marks the package list as already seen, so any package name after it is no longer read as a package — it is forwarded to the test binary as a positional argument and `go test` falls back to `.`. A test-binary flag (`-rapid.checks=N`) ahead of the packages therefore measures the working directory instead of them. See Worker.buildArgs for the same ordering on the mutant builds.

func RunCoverage

func RunCoverage(ctx context.Context, projectDir string, packages []string, coverPkg, tags string, tmpDir string, testFlags []string) (string, error)

RunCoverage runs go test with coverage and returns the profile path. testFlags are the user's --test-flags. Forwarding them here keeps the profile consistent with what the per-mutant runs execute: a test that `-short` skips must not be recorded as covering, or every mutant on its lines would be reported as a survivor instead of NOT_COVERED.

As in MeasureBaseline, the flags land after the package arguments so that an unrecognized one cannot demote them to positional arguments for the test binary — which here would profile the working directory and report every mutant NOT_COVERED.

func ShortFlagFromEnv

func ShortFlagFromEnv() bool

ShortFlagFromEnv reports whether the inner `go test` should be invoked with -short. Extracted from Worker.Test so the env-string equality check is reachable without spinning up a subprocess.

Types

type ExecOpts

type ExecOpts struct {
	TestCPU   int
	Tags      string
	TestFlags []string
	GOROOT    string
}

ExecOpts bundles the inner `go test` knobs forwarded to each worker: TestCPU (0 omits -cpu, letting go test default to GOMAXPROCS), Tags (empty omits -tags), TestFlags (user-supplied flags appended verbatim; nil appends nothing), and GOROOT (the toolchain's, put first on PATH for every test binary as `go test` does; empty leaves PATH alone). Grouped into one struct so NewPool stays within a sane parameter count.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool coordinates parallel mutation testing.

func NewPool

func NewPool(workers int, exec ExecOpts, policy TimeoutPolicy, tmpDir string, srcCache map[string][]byte, projectDir string, testMap *coverage.TestMap) *Pool

NewPool creates a worker pool. See ExecOpts for the inner `go test` knobs (TestCPU, Tags).

func (*Pool) Run

func (p *Pool) Run(ctx context.Context, mutants []mutator.Mutant, onResult ResultCallback)

Run tests all pending mutants in parallel, calling onResult for each completion. Mutant statuses are updated in place on the input slice.

type ResultCallback

type ResultCallback func(m mutator.Mutant)

ResultCallback is called for each completed mutant.

type TimeoutPolicy

type TimeoutPolicy struct {
	// Global is the absolute upper bound (baseline*coefficient). Also
	// the value used when Adaptive is false.
	Global time.Duration

	// Margin scales the observed per-test/per-package sum. 1.0 means
	// "trust the measurement exactly"; values >1 add headroom for GC,
	// scheduler jitter, mutated-code slowdowns, and contention under
	// the parallel mutation phase (which runs at higher concurrency
	// than the coverage build that produced the measurements).
	Margin float64

	// Min is the floor — the smallest value For() will return when
	// adaptive computation produces something tiny. Absorbs cold-start,
	// child fork, and GC-pause overhead that doesn't scale with the
	// underlying test work. Without it a 5ms test gets a 15ms deadline
	// (with Margin=3) and flakes on a busy machine.
	Min time.Duration

	// Adaptive is the master switch. When false, For() always returns
	// Global; the per-mutant tm/m arguments are ignored.
	Adaptive bool
}

TimeoutPolicy decides the per-mutant `go test` deadline. Without adaptive sizing every mutant inherits the same baseline×coefficient timeout, which on multi-package projects pins workers on infinite-loop mutants for whole-suite-sized intervals.

  • Adaptive=false → every mutant gets Global. Behavior matches pre- adaptive gomutants exactly; used as the kill switch.
  • Adaptive=true → per-mutant timeout = clamp(baseSum*Margin, Min, Global) where baseSum is the sum of the mutant's covering tests' durations from the coverage map. A mutant without it gets Global.

The deadline bounds running the mutant's tests, not building their test binaries, which happens first, outside it (see Worker.runGroups).

All clamps point in the safe direction: a missing measurement falls back to a longer timeout, never a shorter one. Worst-case the user sees pre-adaptive wait times; they never see false TIMED_OUT inflation.

func (TimeoutPolicy) For

For returns the deadline for the run of m's covering tests (see Worker.Test), consulting `tm` for per-test timings.

When adaptive, it is the sum of the selected per-test durations — the actual tests this mutant will run via -test.run=^(TestA|TestB)$, in whichever packages they are — scaled by Margin. It covers no build: the tests' binaries are built with the mutant in place before the deadline starts.

A mutant without covering tests runs its whole package, which gets Global: the map's timings don't describe that run, as a test that failed or hung when run alone has none, and a mutant on a line no test covers rarely hangs.

The output is clamped: max(scaled, Min), then min(that, Global). Both clamps fail safe — too-tight measurements widen to Min, and a pathological multiplication can never escape Global.

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker tests a single mutant: it builds the test binary of each package whose tests it runs, with the mutant in place through an overlay, then runs the binary.

func NewWorker

func NewWorker(id int, tmpDir string, policy TimeoutPolicy, sourceCache map[string][]byte, projectDir string, testMap *coverage.TestMap) (*Worker, error)

NewWorker creates a worker with stable temp file paths.

func (*Worker) Test

func (w *Worker) Test(ctx context.Context, m mutator.Mutant) mutator.Mutant

Test applies a mutation and runs go test, returning the updated mutant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL