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 ¶
- type Store
- func (s *Store) ArmBulkGetHold(sub string) (arrived <-chan struct{}, release func())
- func (s *Store) ArmETagMismatch(keySubstring string, n int, notify chan struct{})
- func (s *Store) ArmFailures(keySubstring string, n int, notify chan struct{})
- func (s *Store) ArmGetEmpty(keySubstring string, n int, notify chan struct{})
- func (s *Store) ArmGetFailures(keySubstring string, n int, notify chan struct{})
- func (s *Store) ArmGetHold(sub string) (arrived <-chan struct{}, release func())
- func (s *Store) ArmInitHold() (arrived <-chan struct{}, release func())
- func (s *Store) ArmMultiDeleteHold(sub string) (arrived <-chan struct{}, release func(), done <-chan struct{})
- func (s *Store) ArmMultiHold(sub string) (arrived <-chan struct{}, release func())
- func (s *Store) ArmMultiWriteBehind(sub string) (arrived <-chan struct{}, apply func() error)
- func (s *Store) BulkGet(ctx context.Context, req []state.GetRequest, opts state.BulkGetOpts) ([]state.BulkGetResponse, error)
- func (s *Store) CountBulkGets(sub string) func() int
- func (s *Store) DelayBulkGets(sub string, d time.Duration)
- func (s *Store) FailedCount() int
- func (s *Store) Get(ctx context.Context, req *state.GetRequest) (*state.GetResponse, error)
- func (s *Store) Init(ctx context.Context, meta state.Metadata) error
- func (s *Store) Multi(ctx context.Context, req *state.TransactionalStateRequest) error
- func (s *Store) MultiCancelled() int
- func (s *Store) MultiDeadline() (remaining time.Duration, ok bool)
- func (s *Store) MultiMaxSize() int
- func (s *Store) SetMultiObserver(fn func(*state.TransactionalStateRequest))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
Store wraps an in-memory state store and selectively fails Multi (transactional) operations whose keys contain a configured substring.
func New ¶
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
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
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 ¶
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
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
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
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) ArmInitHold ¶ added in v1.19.0
func (s *Store) ArmInitHold() (arrived <-chan struct{}, release func())
ArmInitHold arms a one-shot hold on daprd's Init of this store. Init blocks until release is called; if its context is done first, Init returns the context's error.
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) ArmMultiHold ¶ added in v1.19.0
ArmMultiHold arms a one-shot hold on the next Multi touching a key containing sub, whatever the operation type. arrived is closed when the Multi is captured; it then blocks until release is called. Unlike the in-memory store it wraps, a held Multi whose request context died while it waited returns that context error, as every real transactional store does: database/sql rolls a transaction back as soon as its context is cancelled. Tests use this to hold a commit while the host cancels the caller. release is idempotent, so it is safe to register with t.Cleanup.
func (*Store) ArmMultiWriteBehind ¶ added in v1.19.0
ArmMultiWriteBehind arms a one-shot write-behind on the next Multi touching a key containing sub: the caller is answered success at once while the request reaches the underlying store only when apply is called, so reads in between serve the state from before the acknowledged write, as they do on a store whose reads lag its writes. Armed from a SetMultiObserver callback it captures the observed Multi itself. apply is idempotent and returns once the request is applied, returning the store's verdict on it, 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) CountBulkGets ¶ added in v1.19.0
CountBulkGets counts every later BulkGet that touches a key containing sub and returns a func reading the count.
func (*Store) DelayBulkGets ¶ added in v1.19.0
DelayBulkGets makes every later BulkGet that touches a key containing sub take at least d longer, as reading a large history does on a real store.
func (*Store) FailedCount ¶
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) Init ¶ added in v1.19.0
Init implements state.Store. The framework calls Init once during its own setup with empty metadata (see statestore.go); only daprd's Init, which the gRPC adapter (component.go) always passes with a component name, is held.
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) MultiCancelled ¶ added in v1.19.0
MultiCancelled returns how many held Multi requests were abandoned because their request context was cancelled while the hold was in place.
func (*Store) MultiDeadline ¶ added in v1.19.0
MultiDeadline returns how much time the context of the most recent Multi had left before its deadline when the request reached the store. ok is false if that context has no deadline, or no Multi has been received.
func (*Store) MultiMaxSize ¶
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.