Documentation
¶
Overview ¶
Package drivertest is the conformance suite every hopper driver must pass.
A driver's tests call Run with a Fixture that hands out isolated, migrated databases and implements the few engine-specific hooks the suite needs to set up situations (an expired lease, a stuck job) that no queue operation produces on its own.
func TestConformance(t *testing.T) {
drivertest.Run(t, pgxFixture{})
}
The suite covers inserting (including unique keys and replace), claiming (order, ownership, expiry, SKIP LOCKED), every finalize transition and its fencing, snooze reasons, leases, leader election, rescue candidates, cancel, retry, TTL expiry, listing, queues, periodic slots, stats, notifications and history maintenance. Engine-specific behavior, such as how partitions are managed, belongs in the driver's own tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fixture ¶
type Fixture[TTx any] interface { // NewDriver returns a driver on a fresh database with hopper's schema // installed, torn down when the test ends. NewDriver(t *testing.T) driver.Driver[TTx] // Begin starts a transaction. The suite calls commit or rollback. Begin(ctx context.Context, t *testing.T, d driver.Driver[TTx]) (tx TTx, commit, rollback func() error) // ExpireLease makes a client's lease expired, as a partition or a long // pause would. ExpireLease(ctx context.Context, t *testing.T, d driver.Driver[TTx], clientID int64) // ExpireLeader makes the leader lease expired. ExpireLeader(ctx context.Context, t *testing.T, d driver.Driver[TTx]) // MakeClaimable moves a job's scheduled time to now. MakeClaimable(ctx context.Context, t *testing.T, d driver.Driver[TTx], id driver.JobID) // AgeAttempt backdates a running job's attempted time by age. AgeAttempt(ctx context.Context, t *testing.T, d driver.Driver[TTx], id driver.JobID, age time.Duration) // CountLive and CountHistory count jobs in the live table and in history. CountLive(ctx context.Context, t *testing.T, d driver.Driver[TTx]) int CountHistory(ctx context.Context, t *testing.T, d driver.Driver[TTx]) int // Exec runs a SQL statement with hopper's tables on the search path, for // rows the suite writes directly, such as those a client of the previous // release leaves behind. QueryText returns the single text value a query // selects, for what the driver's reads do not show. Both report a failure // with t.Error rather than t.Fatal, so the suite may call them from any // goroutine. Exec(ctx context.Context, t *testing.T, d driver.Driver[TTx], query string, args ...any) QueryText(ctx context.Context, t *testing.T, d driver.Driver[TTx], query string, args ...any) string }
Fixture gives the suite a database per test and the hooks it needs.