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 ¶
const ( DefaultExpiryTTL = 750 * time.Millisecond DefaultConcurrency = 16 )
Defaults for Suite.
Variables ¶
This section is empty.
Functions ¶
func FuzzOperations ¶
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()})
}
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.