Skip to content
Source on GitHub (opens in a new tab)
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.

var ErrDead = errors.New("simulated process death")

ErrDead marks a driver boundary lost to a simulated process death.

func Check(evs []event.Event) error

Check validates E2–E4 independently of loop.Step. Incomplete logs are valid: open attempts keep their reservation and retryable effects may remain open.

func CheckBatches(batches [][]event.Event) error

CheckBatches verifies O1/C4: observations cannot outlive their closing record in an atomic append group. Each supplied batch must represent one append.

func Intent(evs []event.Event, id string, attempt int) error

Intent verifies C3 at the instant of dispatch using the surviving log, so a test can prove action never precedes an acknowledged intent.

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.

func NewBarrier() *Barrier

NewBarrier returns a dispatch barrier with owned channels.

func (b *Barrier) Wait(ctx context.Context) error

Wait announces dispatch and waits for explicit release or cancellation.

type Boundary string

Boundary 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.

func (l *Log) Adopt(ctx context.Context, session string, t lease.Token) (uint64, error)

Adopt fails after death rather than consulting surviving state.

func (l *Log) Append(ctx context.Context, session string, seq uint64, t lease.Token, evs ...event.Event) error

Append injects the selected boundary, preserving atomic writes in the base.

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.