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

fault

package
v1.18.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fault provides a state.Store implementation that wraps the in-memory store and lets tests deterministically inject transient transactional save failures keyed by a substring of the operation key. Tests use this to verify that workflow / actor code recovers cleanly from state-store hiccups (no stuck workflows, no orphan reminders).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	*inmemory.Wrapped
	// contains filtered or unexported fields
}

Store wraps an in-memory state store and selectively fails Multi (transactional) operations whose keys contain a configured substring.

func New

func New(t *testing.T) *Store

New returns a Store that is functionally identical to the in-memory store until ArmFailures is called.

func (*Store) ArmBulkGetHold added in v1.18.3

func (s *Store) ArmBulkGetHold(sub string) (arrived <-chan struct{}, release func())

ArmBulkGetHold arms a one-shot hold on the next BulkGet touching a key containing sub. arrived is closed when the BulkGet is captured; the call blocks until release is called (or its context is done). release is idempotent, so it is safe to register with t.Cleanup.

func (*Store) ArmETagMismatch added in v1.18.0

func (s *Store) ArmETagMismatch(keySubstring string, n int, notify chan struct{})

ArmETagMismatch arms the store to return a state.ETagError of kind ETagMismatch on the next n matching Multi requests. Use this when a test wants to exercise the orchestrator's peer-write recovery path rather than a generic transient error.

func (*Store) ArmFailures

func (s *Store) ArmFailures(keySubstring string, n int, notify chan struct{})

ArmFailures arms the store to return a synthetic transient error on the next n transactional Multi requests whose operation keys contain keySubstring. n=1 produces a one-shot failure, n=0 disarms. If notify is non-nil it is closed the FIRST time a matching Multi is failed, so callers can synchronise on the failure firing.

func (*Store) ArmGetEmpty added in v1.18.4

func (s *Store) ArmGetEmpty(keySubstring string, n int, notify chan struct{})

ArmGetEmpty arms the store to answer the next n Gets whose key contains keySubstring with an empty response, as a store whose reads lag its own writes would. n=0 disarms. notify, when non-nil, is closed on the first.

func (*Store) ArmGetFailures added in v1.18.4

func (s *Store) ArmGetFailures(keySubstring string, n int, notify chan struct{})

ArmGetFailures arms the proxy to fail the next n Gets whose key contains keySubstring with a transient error. n=0 disarms. notify, when non-nil, is closed on the first injected failure.

func (*Store) ArmGetHold added in v1.18.4

func (s *Store) ArmGetHold(sub string) (arrived <-chan struct{}, release func())

ArmGetHold arms a one-shot hold on the next Get whose key contains sub. The Get blocks until release is called (or its context is done).

func (*Store) ArmMultiDeleteHold added in v1.18.3

func (s *Store) ArmMultiDeleteHold(sub string) (arrived <-chan struct{}, release func(), done <-chan struct{})

ArmMultiDeleteHold arms a one-shot hold on the next Multi containing a Delete operation whose key contains sub. arrived is closed when the Multi is captured; the Multi blocks until release is called (or its context is done); done is closed after the delegated Multi returns. release is idempotent, so it is safe to register with t.Cleanup.

func (*Store) BulkGet added in v1.18.3

func (s *Store) BulkGet(ctx context.Context, req []state.GetRequest, opts state.BulkGetOpts) ([]state.BulkGetResponse, error)

BulkGet shadows the promoted in-memory implementation so an armed hold can block the read between a caller's metadata Get and its bulk entry read.

func (*Store) FailedCount

func (s *Store) FailedCount() int

FailedCount returns the total number of Multi requests that have been failed by this Store since it was constructed.

func (*Store) Get added in v1.18.4

func (s *Store) Get(ctx context.Context, req *state.GetRequest) (*state.GetResponse, error)

Get implements state.Store, honouring armed Get failures, empty answers and holds.

func (*Store) Multi

Multi implements state.TransactionalStore. If the store is armed and the request touches a key containing the armed substring, the request is failed with the armed error; otherwise the request is delegated to the underlying in-memory store.

func (*Store) MultiMaxSize

func (s *Store) MultiMaxSize() int

MultiMaxSize advertises no per-transaction key limit so the test can freely batch saves through the in-memory implementation.

func (*Store) SetMultiObserver added in v1.18.0

func (s *Store) SetMultiObserver(fn func(*state.TransactionalStateRequest))

SetMultiObserver registers a callback invoked synchronously on every Multi before delegation. Tests use it to inspect the ETag of specific upserts. nil clears any previously registered observer.

Jump to

Keyboard shortcuts

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