Help us shape the future of Go! Take the 2026 Go Developer Survey

storetest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package storetest is the acceptance suite every leaderelection.Store implementation must pass.

The election's safety argument assumes a precise set of behaviours from the store: that a takeover is atomic, that a fence token never repeats within an election, that a guarded renewal fails rather than silently succeeding against someone else's lease. Those behaviours are easy to get subtly wrong in SQL, and differently wrong in each dialect. Running one suite against every implementation -- including the in-memory reference -- is what keeps the guarantee from being dialect-specific.

A conformant store must pass this suite unchanged when reached directly and when reached through a connection pooler.

Index

Constants

View Source
const (
	DefaultExpiryTTL   = 750 * time.Millisecond
	DefaultConcurrency = 16
)

Defaults for Suite.

Variables

This section is empty.

Functions

func FuzzOperations

func FuzzOperations(f *testing.F, s Suite)

FuzzOperations drives arbitrary operation sequences against a store and checks each result against a model of the contract.

Implementations wire it up as a fuzz target of their own:

func FuzzStore(f *testing.F) {
	storetest.FuzzOperations(f, storetest.Suite{Store: memstore.New()})
}

func Run

func Run(t *testing.T, s Suite)

Run executes the acceptance suite against s.Store.

Types

type Suite

type Suite struct {
	// Store is the implementation under test. Subtests isolate themselves by
	// using distinct election names, so one Store serves the whole suite.
	Store leaderelection.Store

	// ExpiryTTL is the lease duration used by tests that must watch a lease
	// expire in real time. It has to comfortably exceed a round trip to the
	// database: too short and a slow reply expires the lease mid-test.
	// Defaults to DefaultExpiryTTL.
	ExpiryTTL time.Duration

	// Concurrency is how many goroutines contend in the race tests. Defaults
	// to DefaultConcurrency.
	Concurrency int

	// Now, if set, reports the database's current time. Tests use it only to
	// report diagnostics; the suite never compares it against local time.
	Now func(ctx context.Context) (time.Time, error)
}

Suite configures a run of the acceptance tests.

Jump to

Keyboard shortcuts

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