arbiter-test-common-0.1.0.0
arbiter-test-common
Safe HaskellNone
LanguageGHC2024

Arbiter.Test.StateMachine

Description

Parameterized stateful property-based tests for the core job engine, using hedgehog. Works against any MonadArbiter backend via a passed runner and a raw-connection accessor.

Generates random sequences of engine operations against the real database (insert at varying priority, scheduled insert, claim, ack, cancel, suspend, resume, promote, retry, extend-lease, move-to-DLQ, retry-from-DLQ, batch insertcancelDLQ, dedup insert, and the reaper) and checks the core invariants after every step:

  • at most one in-flight job per group (the serialization guarantee)
  • no job exceeds its max_attempts
  • no duplicate live dedup_key
  • no concurrency key has more claimed-in-flight jobs than its effective cap
  • every group summary column matches its recompute from the main table

Generated inserts also carry rate-limit keys and concurrency slots.

A second property (prop_concurrent) generates N independent branches of self-contained actions, runs them concurrently under a gap-free serialization detector (a row trigger that fires inside every claim), then quiesces with a reaper tick and asserts both the detector log and the full settled oracle are clean. All contention is in the generated, shrinkable model. Deterministic guards back the known-critical races.

Synopsis

Documentation

Source #stateMachineSpec :: ArbiterC sm => (forall a. sm a -> IO a) -> Text -> Text -> (forall a. (Connection -> IO a) -> IO a) -> IO () -> Spec

Arguments

:: ArbiterC sm 
=> (forall a. sm a -> IO a)

Runner

-> Text

schemaName

-> Text

tableName

-> (forall a. (Connection -> IO a) -> IO a)

Raw-connection accessor

-> IO ()

Reset (truncate) action

-> Spec 

Parameterized state-machine property suite. The runner executes a backend action against the real database. withConn exposes a raw Connection for the oracle and HOL-detector SQL. reset truncates the test tables.

Source #data SMPayload

A payload carrying optional concurrency and rate-limit keys.

Constructors

SMPayload 

Instances

Instances details
FromJSON SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

ToJSON SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

HasConcurrency SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

HasRateLimit SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

Eq SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

Generic SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

Associated Types

type Rep SMPayload 
Instance details

Defined in Arbiter.Test.StateMachine

type Rep SMPayload = D1 ('MetaData "SMPayload" "Arbiter.Test.StateMachine" "arbiter-test-common-0.1.0.0-inplace" 'False) (C1 ('MetaCons "SMPayload" 'PrefixI 'True) (S1 ('MetaSel ('Just "smMessage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "smConcSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "smRateKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)))))
Show SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

type Rep SMPayload Source # 
Instance details

Defined in Arbiter.Test.StateMachine

type Rep SMPayload = D1 ('MetaData "SMPayload" "Arbiter.Test.StateMachine" "arbiter-test-common-0.1.0.0-inplace" 'False) (C1 ('MetaCons "SMPayload" 'PrefixI 'True) (S1 ('MetaSel ('Just "smMessage") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "smConcSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "smRateKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)))))

Source #holViolTbl :: Text -> Text -> Text

Names of the head-of-line detector's table, function, and trigger.

Source #holInstallSql :: Text -> Text -> [Text]

DDL to install the gap-free HOL detector. A row trigger logs a violation when a job becomes in-flight while another attempts > 0 job in its group already is. The attempts > 0 filter excludes scheduled jobs.

Source #holRemoveSql :: Text -> Text -> [Text]

DDL to remove the HOL detector trigger, function, and violations table.