application

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package application binds retained PostgreSQL scopes to production application settings. It stays separate from the lightweight testkit/postgres helpers so low-level packages can use schema isolation without an infrastructure cycle.

Index

Constants

View Source
const DefaultConcurrency = 8

DefaultConcurrency is the default maximum number of concurrently booted applications per test process. At 4 connections per booted app (2 primary + 2 read), 8 concurrent applications use 32 connections, leaving 68 connections headroom below PostgreSQL's default max_connections ceiling of 100 for schema creation, migrations, and assertion pools.

The limit may be overridden via the FOUNDRY_TEST_APP_CONCURRENCY environment variable with a positive integer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application interface {
	Start(context.Context) error
	Shutdown(context.Context) error
	ShutdownTimeout() time.Duration
	// Done closes only after all owned work and dependency cleanup finish.
	Done() <-chan struct{}
	Migrations() []infrastructure.MigrationTarget
}

Application is satisfied by *application.App without importing application assembly into a feature helper. Build it from Environment.Settings through application.Settings.WithDatabaseScopes before handing it to Start.

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment contains scoped copies of every selected logical connection. It owns migration setup and registers bounded application cleanup through Start.

func Bind

func Bind(settings infrastructure.DatabaseSettings, selections ...Selection) (*Environment, error)

Bind requires every configured connection exactly once. Separate Isolate calls express distinct namespaces; one On call expresses intentional sharing. Test pools use two connections per endpoint and retain the configured global ceiling. This neither mutates original settings nor reconfigures a live pool.

func (Environment) Format

func (Environment) Format(s fmt.State, _ rune)

func (*Environment) Migrate

func (e *Environment) Migrate(ctx context.Context, targets ...infrastructure.MigrationTarget) error

Migrate validates all targets first, then applies one registry/history per physical namespace. Each short-lived primary pool closes before the next opens. Successful migrations and data remain committed if a later group fails.

func (*Environment) Settings

Settings returns caller-owned settings; defaults still alias their named pool.

func (*Environment) Start

Start owns cleanup before migration/startup. Framework and explicit domain migrations commit through the ordinary runner before providers start. A failed attempt also shuts down immediately. HTTP/worker lifetimes remain app-owned; register test clients afterward so their cleanup precedes app shutdown.

Concurrency is bounded to DefaultConcurrency (8) per test process. All apps started within a single top-level test (including subtests) share that test's single concurrency slot. The slot is released after the application has completely shut down.

type Selection

type Selection struct {
	// contains filtered or unexported fields
}

Selection explicitly states which named application connections share a scope. No original deployment endpoint or password survives binding.

func On

func On(scope *pgtest.Scope, names ...database.ConnectionName) Selection

On explicitly maps named application connections to a retained scope.

func (Selection) Format

func (Selection) Format(s fmt.State, _ rune)

func (Selection) WithReads

func (s Selection) WithReads() Selection

WithReads enables a separate bounded read pool against the same opted-in test database/schema. By default all original read routing is explicitly disabled.

Jump to

Keyboard shortcuts

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