harness

package module
v0.0.0-...-0c820e1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package harness is a reusable conformance suite for the msgin sql adapter engine (github.com/kartaladev/msgin/adapter/database/sql). It is authored as its own module (Plan 006 Task 3, ADR 0011) so any dialect author — the built-in postgres/mysql leaf-test modules, a future sqlite dialect, or a third party — can run the SAME behavior contract against their own LeaseDialect/InboxDialect implementation and a real database, without this module (or its testify dependency) ever entering the driver-free engine's module graph.

The harness drives the engine's EXPORTED API only: RunSource, RunLock, RunOutbound, RunOutbox, RunInbox, and RunDialect each take an already-open *sql.DB (the caller/runner provisions the container or database) and a TestKit describing the dialect under test plus the per-dialect SQL primitives the verification queries need but that are deliberately NOT part of the LeaseDialect/InboxDialect SPI (identifier quoting, placeholders, the server-now expression, ...). See TestKit's field docs for why each knob exists.

The harness imports the engine + testify + stdlib database/sql/testing ONLY — no driver, no testcontainers (verified by `go list -deps`). It is a library of test-driver functions; a dialect's own module (or the dbtest runner, for the built-ins) supplies the real database connection and is the first place these functions actually execute against one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialectEngine

func DialectEngine(d msginsql.GroupDialect) string

DialectEngine returns the last element of the GroupDialect implementation's package path — "postgres", "mysql" or "sqlite" for the built-ins — which is the engine token each dialect substitutes into the member-cap rejection's site string ("msgin/sql/<engine>: AddMember"). It is derived from the dialect rather than from TestKit.Name because Name is a display label a runner may override (the shipped MariaDB runner sets Name "mariadb" while running the mysql dialect), and the site names the package that minted the error.

A POINTER-typed dialect derives the same token as its value form. That is not a nicety: GroupDialect's own godoc tells implementers to assert conformance as `var _ msginsql.GroupDialect = (*yourDialect)(nil)`, so a TestKit whose Group is a *yourDialect is the documented shape, and reflect.Type.PkgPath is "" for a pointer type. A nil dialect, or a nil pointer of a named type, is handled without panicking for the same reason (Plan 031 Task 11, review finding R-12).

It is exported so the derivation is assertable from a blackbox test (this module ships no other way to reach it) and so a dialect author outside this module can see the exact token the member-cap assertions will expect.

func RunDialect

func RunDialect(t *testing.T, kit TestKit, db *sql.DB)

RunDialect exercises kit.Lease's SQL directly (bypassing Source/Outbound), reproducing every assertion the pre-split DialectSuite made (Plan 006 Task 3): SchemaExists/EnsureSchema idempotency, the reference DDL (kit.DDL) applying cleanly, Claim bumping delivery_count/lease_epoch and locking the row, the empty-claim case, Ack's fence branches (correct/stale-epoch/ wrong-owner), Nack delaying visibility, expired-lease reclaim, and a delayed Insert staying hidden until visible. It additionally exercises the dialect-author error branch audit R2-2 calls out: kit.DDL and kit.InboxDDL both reject an invalid table identifier with ErrInvalidTableName, so that branch is not silently uncovered when coverage is measured via the concrete dialect's dbtest -coverpkg run.

func RunGroupStore

func RunGroupStore(t *testing.T, kit TestKit, db *sql.DB)

RunGroupStore certifies the msginsql.GroupStore facade + kit.Group (GroupDialect) against a real database on the already-open db: the full msgin.MessageGroupStore contract (idempotent Add, growing snapshot, exclusive ClaimGroup, fenced Settle/Abandon, late-member survival with created_at reset, crashed-lease Expired) PLUS the cross-connection and crash-recovery invariants a durable multi-process aggregation store must uphold that the in-memory reference store cannot exhibit (ADR 0021 §6): H1 concurrent-first-add completion detection, the two-connection claim race, H2 stale-epoch recovery (re-absorbed members, no orphans, fenced stale settle), H-A crash-mid-release re-emitting to the OUTPUT channel via a real *routing.Aggregator reaper, and H-B deadlock-freedom under a high-concurrency same-key add/settle loop.

Cross-connection races drive concurrent goroutines over the SAME db pool: a *sql.DB hands each concurrent operation a distinct physical connection, so the group-row FOR UPDATE lock (or SQLite's BEGIN IMMEDIATE write lock) is genuinely exercised across connections — the transaction-scoped lock is what serializes them, identical to two processes. Each subtest provisions its own fresh table.

func RunInbox

func RunInbox(t *testing.T, kit TestKit, db *sql.DB)

RunInbox exercises the idempotent-consumer dedup inbox (msginsql.InboxDeduper, ADR 0010 D10) against kit.Inbox on the already-open db, reproducing every assertion the pre-split InboxSuite made (Plan 006 Task 3): idempotency across redelivery, the atomic-with-business-tx silent-loss guard (a rolled-back attempt is genuinely retryable, never falsely deduped), the MySQL-family INSERT-IGNORE false-positive guard (skipped on a non-MySQL-family kit — audit R2-2's dialect-error-branch exercise), manual Purge retention, Ready/EnsureSchema (including applying the reference InboxDDL), the missing-unique-constraint fail-fast, and the sensible "msgin_inbox" default table name.

func RunLock

func RunLock(t *testing.T, kit TestKit, db *sql.DB)

RunLock exercises the lock/FOR UPDATE strategy (ADR 0010 D5) end-to-end and at the dialect level against kit.Lease (asserted to also implement msginsql.LockDialect — the segregated lock SPI) on the already-open db. It reproduces every assertion the pre-split LockSuite made (Plan 006 Task 3): the single-row claim cap, the always-commit Nack (delivery_count climbs across redeliveries under the DEFAULT retry policy), the crash-reverts-only- the-in-flight-attempt semantics, empty/error claim rollback with no connection leak, shutdown NOT redelivering in-flight lock deliveries (detached claim tx), a separate-pool DLQ draining without deadlock, the corrupt-headers penalty-NackLock skip, the requeue=false collapse, and the deadline-Nack rollback arm. kit.OpenDB is required here (and only here) for the separate-pool DLQ assertion.

Every assertion here is CORRECTNESS-only (a claim exclusively owns its row until settle; a settle either commits or rolls back the WHOLE in-flight attempt; no message is lost or double-delivered) — never a non-blocking/throughput assumption — so a single-writer engine passes the same contract unchanged (audit F8).

func RunOutbound

func RunOutbound(t *testing.T, kit TestKit, db *sql.DB)

RunOutbound exercises the INSERT msginsql.Outbound channel adapter against kit.Lease on the already-open db, reproducing every assertion the pre-split OutboundSuite made (Plan 006 Task 3): the producer hot path (frames headers + JSON payload into a row), the produce/consume round-trip with a paired Source on the same table, use as a msgin.RetryPolicy.DeadLetter AND a endpoint.WithInvalidMessageSink target, Ready/Send surfacing ErrSchemaNotReady, and Send's defensive framing/payload error branches.

func RunOutbox

func RunOutbox(t *testing.T, kit TestKit, db *sql.DB)

RunOutbox exercises Outbound.Send's shared-transaction policy (ADR 0010 D8) against kit.Lease on the already-open db, reproducing every assertion the pre-split OutboxSuite made (Plan 006 Task 3): the atomicity of a business write + the outbox INSERT under a caller-owned *sql.Tx (both commit and rollback branches), commit-gated visibility to a concurrent Source.Poll, every resolveQuerier branch (no resolver / resolver error / strict no-tx / opportunistic no-tx), and the borrowed-tx never-committed/rolled-back invariant.

func RunQueueStore

func RunQueueStore(t *testing.T, kit TestKit, db *sql.DB)

RunQueueStore exercises the msginsql.QueueStore facade (Enqueue = INSERT via the paired Outbound; Claim = lease/claim via the paired Source, both over the SAME table) against kit.Lease on the already-open db. It certifies the facade is durable across the Enqueue/Claim/Ack lifecycle, redelivers a Nacked (requeue=true) claim, and gives two competing QueueStores over the same table disjoint claims — the properties a durable msgin.ChannelStore backing a channel.QueueChannel must uphold (Spec 007, ADR 0018). Each subtest provisions its own fresh table (kit.Lease.EnsureSchema), so subtests never interfere.

func RunSource

func RunSource(t *testing.T, kit TestKit, db *sql.DB)

RunSource exercises the lease/claim msginsql.Source end-to-end (through the real msgin runtime, NewConsumer + Run) and at the fenced-settle level, against kit.Lease on the already-open db. It reproduces every assertion the pre-split SourceSuite made (Plan 006 Task 3): the happy at-least-once path, climbing delivery_count on redelivery, the stale-lease fence, Ready/Poll ErrSchemaNotReady, the corrupt-headers penalty-Nack skip, the requeue=false collapse, ErrStaleLease on both Ack and Nack, WithLockedBy, and raw-driver-error passthrough under a canceled context. Each subtest provisions its own fresh table (kit.Lease.EnsureSchema), so subtests never interfere with one another.

Concurrency assertions here are CORRECTNESS-only (a fenced settle either applies or reports ErrStaleLease; a redelivered row is never lost) — never a non-blocking/throughput assumption — so a single-writer engine passes the same contract unchanged (audit F8).

Types

type TestKit

type TestKit struct {
	// Name identifies the engine under test (e.g. "postgres", "mysql",
	// "mariadb") for subtest names and diagnostic messages. Required.
	Name string

	// MySQLFamily reports whether this engine speaks MySQL-family SQL (MySQL
	// itself, or a wire-compatible derivative such as MariaDB). It gates the
	// harness assertions that are genuinely engine-specific — currently the
	// INSERT-IGNORE false-positive guard (RunInbox), which has no equivalent
	// on Postgres (ON CONFLICT ... RETURNING is exact, never demotes an
	// error) — so a non-MySQL-family TestKit skips exactly that assertion
	// rather than the harness silently mis-asserting engine-specific SQL.
	MySQLFamily bool

	// SingleWriter reports whether the engine serializes all writers on a
	// single database-wide write lock (SQLite). It gates ONLY
	// RunOutbox/CommitGatesVisibility, which holds an uncommitted write
	// transaction open while a concurrent Source.Poll issues a claim UPDATE on
	// the pool: on an MVCC engine (Postgres/MySQL) the pool claim returns empty
	// cleanly, but on a single-writer engine it blocks on the held writer lock
	// for the full busy_timeout and then fails SQLITE_BUSY. The zero value
	// (false) preserves the existing Postgres/MySQL behavior (audit F1, ADR 0012 D8).
	SingleWriter bool

	// Lease is the LeaseDialect under test — the dialect a real
	// NewPollingSource/NewOutboundAdapter would be constructed with. Required
	// for RunSource, RunOutbound, RunOutbox, RunDialect, and (via a
	// LockDialect type-assertion) RunLock.
	Lease msginsql.LeaseDialect

	// Inbox is the InboxDialect under test — the dialect a real
	// NewInboxDeduper would be constructed with. It is deliberately a
	// separate field (not derived from Lease) because InboxDialect is its
	// own segregated SPI (ADR 0010 D10): a dialect author may supply an
	// InboxDialect value distinct from their LeaseDialect. Required for
	// RunInbox.
	Inbox msginsql.InboxDialect

	// Group is the GroupDialect under test — the dialect a real
	// msginsql.NewGroupStore would be constructed with. It is its own
	// segregated SPI (ADR 0021 §3): group-keyed idempotent add, a per-group
	// lease, claimed-set fencing, and an expiry scan are not row-oriented
	// queue operations, so a GroupDialect value is supplied separately from
	// Lease/Inbox. Required for RunGroupStore.
	Group msginsql.GroupDialect

	// GroupDDL returns the engine's reference CREATE TABLE statements
	// (group-lease table + member table + indexes) for the durable Aggregator
	// group store — the harness peer of the per-dialect
	// postgres.GroupDDL/mysql.GroupDDL/sqlite.GroupDDL package functions, and
	// itself exercises those functions' ValidateIdent guard (RunGroupStore
	// calls it with both a valid and a deliberately invalid identifier).
	// Required for RunGroupStore.
	GroupDDL func(table string) (string, error)

	// Quote wraps a raw identifier in the engine's quoting style (backticks
	// for MySQL-family, double quotes for Postgres) for the RAW verification
	// SQL the harness issues directly (row counts, column probes) — NOT used
	// by the dialect under test, which quotes its own identifiers
	// internally. Required.
	Quote func(ident string) string

	// Placeholder renders the nth (1-based) bind placeholder for the engine
	// ("?" for MySQL-family, "$n" for Postgres), for the harness's own raw
	// verification SQL. Required.
	Placeholder func(n int) string

	// NowExpr is the engine's current-UTC-time SQL expression, used by the
	// harness's raw verification SQL so a comparison against a
	// dialect-written timestamp uses the SAME clock/expression the dialect
	// itself compares against (e.g. MySQL persists via UTC_TIMESTAMP(6), a
	// session-timezone-independent expression; NOW() would not match).
	// Required.
	NowExpr func() string

	// HeadersTextExpr is the SELECT expression that returns the framed
	// headers column as clean text bytes for the engine (e.g. Postgres casts
	// jsonb to text to avoid the binary-format prefix; MySQL's JSON column
	// already returns text bytes as-is). Required for RunOutbound.
	HeadersTextExpr func(col string) string

	// DDL returns the engine's reference CREATE TABLE (+ claim index)
	// statement for the lease/claim schema — the harness peer of the
	// per-dialect postgres.DDL/mysql.DDL package functions, and itself
	// exercises those functions' ValidateIdent guard (RunDialect calls it
	// with both a valid and a deliberately invalid identifier). Required for
	// RunDialect.
	DDL func(table string) (string, error)

	// InboxDDL returns the engine's reference CREATE TABLE (+ retention
	// index) statement for the dedup-inbox schema — the harness peer of the
	// per-dialect postgres.InboxDDL/mysql.InboxDDL package functions.
	// Required for RunInbox.
	InboxDDL func(table string) (string, error)

	// OpenDB opens an ADDITIONAL, independently-pooled *sql.DB connection to
	// the same test database as the *sql.DB RunLock is called with. It
	// exists for exactly one assertion (RunLock's separate-pool DLQ test,
	// ADR 0010 D5): proving a lock-strategy consumer whose source pool is
	// capped at one connection can still dead-letter through a DIFFERENT
	// pool without deadlock. The property under test is pool separation
	// (an independent *sql.DB's connection limit and connection set), not
	// physical-container separation, so a fresh connection to the SAME
	// database via a new *sql.DB satisfies it. Required for RunLock only;
	// the other RunXxx functions never call it.
	OpenDB func(t *testing.T) *sql.DB
}

TestKit is everything a RunXxx conformance function needs to exercise one dialect: the dialect under test (satisfying the engine's exported SPI) plus the per-dialect SQL primitives the harness's OWN verification queries need but that are deliberately not on LeaseDialect/InboxDialect (identifier quoting, placeholders, the server-now expression, the headers→text cast, and the reference-DDL builders — a string-returning DDL method cannot safely revalidate an identifier, so it is never an SPI method; ADR 0010 D3, ADR 0011). A dialect author supplies one TestKit value per engine (e.g. one for Postgres, one for MySQL/MariaDB) and passes it to every RunXxx the dialect wants certified.

Jump to

Keyboard shortcuts

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