testkit/crashtest
import "github.com/barevoidco/zelk/core/testkit/crashtest"Package crashtest supplies deterministic failure injection and an independent event-log checker for durability tests. It never drives the production reducer.
Variables
Section titled “Variables”var ErrDead = errors.New("simulated process death")ErrDead marks a driver boundary lost to a simulated process death.
func Check(evs []event.Event) errorCheck validates E2–E4 independently of loop.Step. Incomplete logs are valid: open attempts keep their reservation and retryable effects may remain open.
CheckBatches
Section titled “CheckBatches”func CheckBatches(batches [][]event.Event) errorCheckBatches verifies O1/C4: observations cannot outlive their closing record in an atomic append group. Each supplied batch must represent one append.
Intent
Section titled “Intent”func Intent(evs []event.Event, id string, attempt int) errorIntent verifies C3 at the instant of dispatch using the surviving log, so a test can prove action never precedes an acknowledged intent.
Barrier
Section titled “Barrier”type Barrier struct { Entered chan struct{} Release chan struct{} // contains filtered or unexported fields}Barrier announces entry and blocks dispatch until released or cancelled. The caller owns the goroutine using Wait and must join it during teardown.
NewBarrier
Section titled “NewBarrier”func NewBarrier() *BarrierNewBarrier returns a dispatch barrier with owned channels.
Barrier.Wait
Section titled “Barrier.Wait”func (b *Barrier) Wait(ctx context.Context) errorWait announces dispatch and waits for explicit release or cancellation.
Boundary
Section titled “Boundary”type Boundary stringBoundary selects how the chosen append fails.
const ( Before Boundary = "before" After Boundary = "after" AmbiguousLanded Boundary = "ambiguous_landed" AmbiguousAbsent Boundary = "ambiguous_absent" Conflict Boundary = "conflict" ReadFailure Boundary = "read_failure" // CancelRead and LeaseRead invoke OnRead while resolving a landed ambiguity. CancelRead Boundary = "cancelled_read" LeaseRead Boundary = "lease_lost_read")The injected append outcomes.
type Log struct { // OnRead injects cancellation or authority loss during ambiguity resolution. OnRead func() error
store.LogStore At int Boundary Boundary Batches [][]event.Event // contains filtered or unexported fields}Log fails exactly the At-th append. After a simulated death it never blocks and every operation fails. Base is the surviving durable backing store. Configure it before use; inspect Batches only after its driver has joined.
Log.Adopt
Section titled “Log.Adopt”func (l *Log) Adopt(ctx context.Context, session string, t lease.Token) (uint64, error)Adopt fails after death rather than consulting surviving state.
Log.Append
Section titled “Log.Append”func (l *Log) Append(ctx context.Context, session string, seq uint64, t lease.Token, evs ...event.Event) errorAppend injects the selected boundary, preserving atomic writes in the base.
Log.Read
Section titled “Log.Read”func (l *Log) Read(ctx context.Context, session string, from uint64) iter.Seq2[event.Event, error]Read fails after death or when an ambiguous read-back is faulted.