testhelpers

package
v0.0.0-...-cb875f4 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: OSL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await[T any](t *testing.T, done <-chan T) T

Await returns the value a background writer sends on done, failing fast instead of hanging until the go test timeout when the writer is stuck.

func WaitForLockWait

func WaitForLockWait(ctx context.Context, t *testing.T, db LockDB, queryLike string)

WaitForLockWait blocks until some backend is waiting on a lock in a statement matching queryLike (a SQL LIKE pattern; "" matches any), which proves the writer under test is queued behind the footprint.

Types

type Footprint

type Footprint struct {
	pgx.Tx
	Executions []string
}

Footprint stands in for the editor command's lock footprint on one plan so the race tests of legacy writers run before the command exists: the plan row FOR UPDATE, then its executions ordered FOR UPDATE, then its accounts FOR SHARE. It does NOT take the command's first two lock levels, the identity advisory lock and the sorted provider advisory locks (LockPlanProvidersTx). The embedded Tx is the command's transaction: Exec applies the command's writes (SetManaged, inserted roots) and Commit/Rollback end it. Executions lists the rows the footprint locked, i.e. what the command captured: a writer that committed before the footprint must appear here.

Swap contract for the ExecutePlanScheduleCommand race tests: replace HoldCommandFootprint with the real command paused after its capture, wrapped as a *Footprint (Tx = the command's transaction, Executions = its captured set). Then (1) the notifier claim queues first on the provider advisory lock, so its WaitForLockWait pattern changes from "%FOR UPDATE%" to the advisory wait (wait_event 'advisory'; match the pg_advisory_xact_lock statement); (2) the direct Exec/QueryRow calls of the retry, prune and account-delete tests become the command's own writes and reads; every other assertion stays.

func HoldCommandFootprint

func HoldCommandFootprint(ctx context.Context, t *testing.T, db LockDB, planID string) *Footprint

HoldCommandFootprint opens the footprint on planID. The transaction rolls back at test end unless the test ended it first.

func (*Footprint) SetManaged

func (f *Footprint) SetManaged(ctx context.Context, t *testing.T, planID string)

SetManaged writes the editor marker inside the footprint's transaction.

type LockDB

type LockDB interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

LockDB is the slice of a pool the lock helpers need. The config store's dbConn and a *pgxpool.Pool both satisfy it.

type PostgresContainer

type PostgresContainer struct {
	Container testcontainers.Container
	Config    *database.Config
	DB        *database.Connection
}

PostgresContainer wraps a testcontainers PostgreSQL instance.

func RequirePostgresContainer

func RequirePostgresContainer(ctx context.Context, t *testing.T) *PostgresContainer

RequirePostgresContainer starts a PostgreSQL test container for t, skipping the test only when this environment has no usable Docker provider and failing loudly for every other error.

Drawing that line is the whole point (issue #1597). "No usable Docker daemon" is an environment fact and the one legitimate reason to skip, so it is probed explicitly before anything is started. Past that probe the daemon answered a health check, which makes a container that still refuses to come up -- a missing image, a database that never accepts connections -- a real failure. Reporting it as a skip would turn a broken run green, which is indistinguishable from a run that had nothing to say.

The probe owns the whole environment side of that line, so a daemon that is present but unhealthy skips too, rather than failing.

Callers remain responsible for Cleanup, matching SetupPostgresContainer.

func SetupPostgresContainer

func SetupPostgresContainer(ctx context.Context, t *testing.T) (*PostgresContainer, error)

SetupPostgresContainer creates and starts a PostgreSQL test container.

func (*PostgresContainer) Cleanup

func (c *PostgresContainer) Cleanup(ctx context.Context) error

Cleanup terminates the test container and closes database connection.

func (*PostgresContainer) ResetDatabase

func (c *PostgresContainer) ResetDatabase(ctx context.Context) error

ResetDatabase drops and recreates all tables (useful for clean state).

func (*PostgresContainer) TruncateTables

func (c *PostgresContainer) TruncateTables(ctx context.Context, tables ...string) error

TruncateTables removes all data from tables (useful between tests).

Jump to

Keyboard shortcuts

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