Skip to main content

Crate headgate_testkit

Crate headgate_testkit 

Source
Expand description

headgate-testkit — the in-process test double: a complete in-memory Store so handler code, retry behavior, steps, and runner wiring can be tested with no database at all (River’s rivertest, asynq’s asynqtest). The Go twin is go/headgatetest; both keep the same split:

FAITHFUL: the transition table (every ack outcome, fence-gated identity, LeaseRejected for a superseded holder), attempts vs crash_attempts, quarantine at the crash limit, job uniqueness uniqueness in both modes, retention policy ephemeral retention-0 delete, retention and eviction contract retention eviction (quarantined exempt), per-partition round-robin admission, priority ordering, duty leases.

SIMPLIFIED, capability-honestly (runtime capability boundary): caps() is 0 — no Transactional (so once/step_once error, as they must without a real transaction), no Inspect (scheduler/operations/quarantine duties idle), no Notifying (workers poll). Like the SQL backends it admits state = available only — pair admit with promote_due (the worker and testing::drain already do). An unconfigured rate class is UNLIMITED here; configure one with MemStore::set_rate_limit. Time is the store’s own clock and tests can freeze or step it — no sleeps.

Structs§

Enqueued
A description of an enqueue. kind is required; every other field is an optional matcher, and None means “do not care”.
MemStore
MysqlTestDatabase
One migrated MySQL database. opts can be cloned into a mysql_async::Pool without re-parsing or exposing credentials.
PostgresTestDatabase
One migrated Postgres schema. Use config to construct a pool/store; it carries the schema in the startup search_path, so every pooled connection sees the same isolated namespace.
RedisTestNamespace
A process-unique Redis key prefix. Redis’s schema boundary is already an explicit prefix in both drivers, so tests do not need a scarce numbered logical database and never call FLUSHALL/FLUSHDB.
TestDatabaseError

Traits§

EnqueuedJobs
Whatever a test double can list back. Implemented for MemStore; a live backend implements it over Inspect::list_jobs in the test that needs it.

Functions§

assert_enqueue_backpressure
Shared live-backend proof for bounded enqueue. It deliberately drives contention: 64 producers race for 25 slots, then the helper verifies idempotent replay, atomic batch rejection, capacity release on terminalization, lowering below current depth, and disabling the policy. Every assertion uses the public Store/Inspect ports.
assert_enqueued
find_enqueued, panicking with that message. The assertion form.
assert_sticky_routing
Shared live-backend proof for strict sticky routing. A 5,000-job high-priority backlog pinned to another worker must not fill the bounded candidate draw and hide the caller’s pinned or ordinary work. Rate-limited requeue then proves the route is durable lifecycle state rather than lease metadata.
find_enqueued
Find the enqueued jobs matching want, or an error saying what was there instead.