Documentation
¶
Overview ¶
Package testutil holds helpers for tests that must prove a concurrent interaction actually happened, rather than passing because the scheduler happened to keep the two sides apart (#658).
The rule these helpers encode: a concurrency test witnesses BOTH sides with positive counters, runs until every witness holds or a deadline fails it, and prints every counter in its failure message. A test that counts only one side, or stops when one side finishes, can pass vacuously on a broken implementation — which is exactly what the original TestParallelBranchSymlinkRace did.
Lives in internal/ so it is not part of the public API surface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eventually ¶
Eventually polls cond every poll until it returns true. If deadline elapses first the test fails with msg and the deadline, so the record says WHAT never happened rather than just that something timed out.
func Overlap ¶
func Overlap(t testing.TB, deadline time.Duration, step func() bool) (witnessed bool, iterations int)
Overlap calls step repeatedly until it returns true (every witness the test needs has been observed) or deadline elapses. It reports whether the overlap was witnessed and how many steps ran.
The caller decides what step does — typically one attempt of the racing operation plus a check of the counters — and what to do on a false return (fail with every counter printed). Overlap itself never fails the test: a deadline is a verdict for the caller to render with its own diagnostics, not a bare timeout.
Types ¶
type Witness ¶
type Witness struct {
// contains filtered or unexported fields
}
Witness tracks named counters ("sides" of an interaction). Declared names print first, in declaration order, so a failure message reads the same way every time; sides hit without being declared are appended.
func NewWitness ¶
NewWitness declares the sides the test intends to observe. Every declared side is printed by String even while its count is zero.
func (*Witness) Count ¶
Count returns how many times side name was observed (0 for an unknown side).