controllercheck

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 9 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.

README

Registration controller properties

The registration campaign uses the real Reconciler in a sequential world with independent authoritative Slurm records and informer snapshots, Kubernetes fake storage, a typed deterministic queue, and a virtual clock. Only the reusable controllercheck package was imported from the Pod-cleanup prototype.

File Responsibility
property_test_contract_test.go Safety rules, convergence, and recovery assumptions
property_test_world_test.go Actions, service fakes, fault boundaries, snapshots, and reconciliation
property_test_workloads_test.go Workload generators and independent allocation intent
property_test_registration_test.go Pure survivor, submission guard, and identity properties
property_test_allocation_test.go Component matching under permutation and incomplete allocations
campaign.go Independent properties, recovery, restart stability, and traces
queue.go Generic queue with deduplication, deadlines, and deterministic ordering

Running

Run these commands from slurm-bridge with the workspace's direnv environment. The existing unit target runs the pure properties, harness checks, and campaign:

GOWORK=off make test

No environment variable or separate Make target is needed. make test disables test-result caching so each campaign executes afresh. The campaign defaults to Rapid's 100 histories per rule and average 100 steps. For a longer nightly campaign or a single-rule replay, invoke the Go test directly:

GOWORK=off go test -race \
  ./internal/controller/registration -run '^TestRegistrationContract$' \
  -count=1 -rapid.checks=1000 -rapid.steps=300

GOWORK=off go test -race \
  ./internal/controller/registration \
  -run '^TestRegistrationContract/always/duplicate-cancellation$' \
  -count=1 -rapid.seed=1 -rapid.checks=100 -rapid.steps=300

Rapid prints replay seeds and shrinks failures. Keep the step count when replaying seeds. Saved counterexamples go under the test package's testdata/rapid directory; -rapid.nofailfile disables saving. Every attempt, including shrinking, starts with a fresh world. Each contract rule is a separate subtest, so one failing rule does not prevent the others from running.

Contract and scope

The campaign creates standalone Pods, Job-owned Pods, native gang PodGroups, CompositePodGroups with two or three heterogeneous components, and LWS parents with two or three independent replicas. Gang components and LWS replicas each have two or three members. Pod names can be reused after deletion. The model does not run the scheduler, Pod cleanup controller, or workload controllers. It does not model parallel controller workers or arbitrary stale Kubernetes reads. Histories start empty, registered, or running; the latter two phases are reached through the real reconciler before disturbances begin. This gives later actions such as binding useful exposure during histories, instead of registering most workloads only during final recovery. The test log reports completed action counts.

Actions create workloads, delete Pods, advance the Slurm cache, process a ready key, advance time, cancel or start a job externally, create a competing allocation, inject a pre-upgrade allocation, bind one Pod, arm a fault, heal, restart, and mark the informer unsynchronized. Slurm start and cancel actions apply to the entire allocation, including every heterogeneous component. Competing allocations model another writer or a replayed submission and exercise duplicate recovery without depending on a rare random sequence of faults and cooldown expiry. Faults occur before a mutation or after it commits but before its reply reaches the controller. Slurm submission writes held records using the real ExternalJobInfoFor; a lost submission reply returns ID zero. Kubernetes patches and deletion, Slurm submission, and controller cancellation invoke the campaign's observer after each committed effect.

Binding requires an unbound, non-deleting Pod with no scheduling gates and a job label naming a running live allocation on the chosen node. It binds one member at a time, so restarts can encounter partially bound gangs. Some generated Pods carry an unrelated gate and cannot bind while it remains. The world never performs automatic Pod cleanup when Slurm jobs finish.

Pre-upgrade injection targets complete, unbound native PodGroups. It writes a released pending job with the original Pod UID list and no group identity, matching the scheduler's pre-MR write format. Cache advancement discovers it normally. The oracle associates legacy records with independently generated membership, so adoption and conflicts with modern allocations use the same contract. Composite groups had no released legacy format; older name-only comments remain outside this campaign.

Snapshots contain stored Pods, authoritative Slurm records, recorded effects, and immutable workload intent captured at creation (identity and component membership). Expected membership is independent of the production IR translator. They never query the current cache. Submission effects preserve the cache records observed at that boundary so the contract can detect submission against an already indexed unfinished allocation. They also preserve the authoritative bound Pod keys at submission, so deleting or binding a Pod later cannot change that evidence. Cancellation effects preserve the preceding live records so the contract can verify that another unfinished allocation exists.

A label must identify a Slurm record listing that Pod UID. Cancellation retains a terminal Slurm record: record ownership and unfinished-allocation liveness are separate requirements. This model assumes Slurm does not purge records while Pods still reference them. The gate must disappear in the patch publishing the label; unrelated gates must survive. Controller cancellation requires another unfinished allocation for the same identity; a sibling heterogeneous component does not count as a survivor. The controller must never patch a bound Pod or submit an allocation whose identity has a bound member.

Recovery stops new workloads, external state transitions, and faults. It fully advances the informer, marks it synchronized, advances virtual time beyond the submission cooldown, and fairly processes ready keys. Every allocation with its required quorum must converge to one unfinished allocation, correct component labels (including heterogeneous leader and offset), and no registration gate within 32 recovery ticks. LWS replicas must converge independently. Generated gangs require every original member; deleting one can remove quorum, and recovery does not replace it. Safety still applies to incomplete gangs, but convergence does not require submitting them. A running, partially bound gang must still converge for its unbound members. If a bound member's job is canceled externally, convergence excludes that allocation: submission is forbidden while a member is bound, and cleanup belongs to the Pod controller. Recovery also checks further progress and a fresh reconciler. Restart loses the queue and cooldown cache but reconstructs events from Pod and synchronized Slurm startup lists.

Only the injected transport error is retryable. Unexpected errors fail the campaign, including errors joined with an injected error. A failure to converge must be investigated as a controller defect or an explicit missing recovery assumption; it must not be hidden with a scenario-specific exception.

Documentation

Overview

Package controllercheck explores generated controller lifecycles against a shared contract. Environments supply their own state, actors, and cache models.

Index

Constants

This section is empty.

Variables

View Source
var ErrInjected = errors.New("injected transport failure")

Functions

func Explore

func Explore[S any](t *testing.T, contract Contract[S], factory func(*rapid.T) Campaign[S])

Explore runs each rule as an independent Rapid property over the same whole- controller model. A failing property does not prevent the remaining subtests from running. Every generated history and shrinking attempt gets a fresh world. Use Go's -run flag to select a rule, and Rapid's flags for shrinking and replay.

func ExploreParallel

func ExploreParallel[S any](t *testing.T, contract Contract[S], factory func(*rapid.T) Campaign[S])

ExploreParallel runs independent rules concurrently. Factories must create isolated worlds, including clients, caches, fault injection, and traces.

Types

type Campaign

type Campaign[S any] struct {
	Snapshot func(context.Context) (S, error)
	// Actions draw parameters from current state. Skip before mutation when an
	// action is unavailable. Every shrinking attempt gets a fresh campaign.
	Actions map[string]func(*rapid.T) error
	// ObserveEffects installs a hook called after every committed controller
	// side effect. The hook records violations without changing controller flow.
	ObserveEffects func(func())
	// Recover stops disturbances and establishes the contract's assumptions.
	// Progress fairly schedules the actors relied on by Eventually.
	Recover       func(context.Context) error
	Progress      func(context.Context) error
	Restart       func(context.Context) error
	Retryable     func(error) bool
	RecoverySteps int
	Trace         *Trace
}

Campaign explores a whole controller environment. There is no distinguished reconcile key or cleanup phase: the environment owns lifecycle transitions, queues, clocks, caches, and the real controller(s) under test.

type Contract

type Contract[S any] struct {
	Always     []Rule[S]
	Eventually []Rule[S]
}

type FailureMode

type FailureMode string
const (
	BeforeCommit FailureMode = "before-commit"
	AfterCommit  FailureMode = "after-commit"
)

type Faults

type Faults struct {
	Trace *Trace
	// contains filtered or unexported fields
}

Faults intercepts named side effects. Each armed fault fires once, on the next matching operation. It is deliberately sequential, like the campaign runner. The same mechanism can wrap Kubernetes, Slurm, or another external API.

func (*Faults) Arm

func (f *Faults) Arm(operation string, mode FailureMode)

func (*Faults) Call

func (f *Faults) Call(operation string, commit func() error) error

func (*Faults) Heal

func (f *Faults) Heal()

type Queue

type Queue[K comparable] struct {
	Now time.Duration
	// contains filtered or unexported fields
}

Queue is a sequential, deterministic scheduling model usable by real event handlers. It models deduplication and deadlines, not worker concurrency, queue priority, or client-go's exact rate limiter. No goroutines or wall-clock sleeps. Call Get only when Len()>0; unlike a production queue, an empty Get panics.

func NewQueue

func NewQueue[K comparable](compare func(K, K) int) *Queue[K]

func (*Queue[K]) Add

func (q *Queue[K]) Add(r K)

func (*Queue[K]) AddAfter

func (q *Queue[K]) AddAfter(r K, delay time.Duration)

func (*Queue[K]) AddRateLimited

func (q *Queue[K]) AddRateLimited(r K)

func (*Queue[K]) Done

func (q *Queue[K]) Done(K)

func (*Queue[K]) Forget

func (q *Queue[K]) Forget(r K)

func (*Queue[K]) Get

func (q *Queue[K]) Get() (K, bool)

func (*Queue[K]) Len

func (q *Queue[K]) Len() int

func (*Queue[K]) NumRequeues

func (q *Queue[K]) NumRequeues(r K) int

func (*Queue[K]) Ready

func (q *Queue[K]) Ready() []K

func (*Queue[K]) ShutDown

func (q *Queue[K]) ShutDown()

func (*Queue[K]) ShutDownWithDrain

func (q *Queue[K]) ShutDownWithDrain()

func (*Queue[K]) ShuttingDown

func (q *Queue[K]) ShuttingDown() bool

func (*Queue[K]) Take

func (q *Queue[K]) Take(r K)

type Rule

type Rule[S any] struct {
	Name      string
	Statement string
	Check     func(S) error
}

Rule is a requirement over authoritative state, independent of the actions used to reach that state. Check must be read-only.

type Trace

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

Trace includes lifecycle actions, intercepted effects, and reconciliation results.

func (*Trace) Logf

func (t *Trace) Logf(format string, args ...any)

func (*Trace) String

func (t *Trace) String() string

Jump to

Keyboard shortcuts

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