storetest

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package storetest provisions throwaway, fully isolated Postgres databases for the akari server's integration tests.

NewStore is the one entry point every integration test uses, in the spirit of Rust's sqlx::test: it hands back a Store backed by a uniquely named database that was just created and migrated, and dropped again when the test finishes. Because no two tests share a database, the suite runs at Go's default package parallelism and individual tests may call t.Parallel. This replaces the older shared-database harness, where each test reset the global `public` schema in one database, so concurrent packages clobbered each other's schema_migrations table and the suite had to be serialized with `go test -p 1`.

Index

Constants

View Source
const EnvDatabaseURL = "AKARI_TEST_DATABASE_URL"

EnvDatabaseURL is the environment variable that opts a run in to the integration tests. Its value is a normal Postgres URL; only the host and credentials are used to reach the server, since each test's database is created beside the one the URL names rather than being it.

View Source
const (

	// EnvMaxLiveStores overrides defaultMaxLiveStores, so a run against a Postgres
	// with a different connection ceiling can retune the gate without a recompile.
	EnvMaxLiveStores = "AKARI_TEST_MAX_STORES"
)

Connection budget. Every test provisions its own database and opens a pool against the one shared Postgres, so the suite's peak connection load is the number of test Stores live at once times the per-pool cap. Two constants bound that product:

  • poolMaxConns (C) caps a single Store's pool.
  • maxLiveStores (N) caps how many Stores are live at once, and it does so ACROSS every `go test` binary, not just within one package's process. The storeGate below is a counting semaphore backed by advisory file locks in a temp directory keyed to the Postgres instance, so every binary aimed at that server draws from the same N slots. A plain in-process semaphore cannot do this (each package `go test` compiles is its own binary with its own memory), which is why `go test ./...` no longer needs a `-p` pin to stay bounded.

The ceiling is N*C = 32*4 = 128 connections, under the 200 max_connections .eph configures, leaving room for the transient CREATE/DROP maintenance connections and the dev server's pool under `eph run`. It holds regardless of `-p` or GOMAXPROCS, since the gate spans processes. Set AKARI_TEST_MAX_STORES to tune N (a smaller Postgres wants a smaller N; more headroom allows a larger one).

As before, the ceiling is a worst case, not the steady state: pgx opens pool connections lazily (pool_min_conns defaults to 0), so a pool holds only what its test uses at once. Almost every test sits at one or two connections and only the concurrent-ingest test reaches C, so a full run peaks well under the ceiling.

Variables

This section is empty.

Functions

func NewStore

func NewStore(t *testing.T) *store.Store

NewStore returns a Store backed by its own isolated, freshly migrated database. The test is skipped when EnvDatabaseURL is unset, so a developer without a Postgres handy still gets a green (skipped) run.

The database is dropped on t.Cleanup with WITH (FORCE), which terminates any connection still attached. That keeps cleanup robust when a test fails or leaves its pool open, so a run never leaks databases behind it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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