riversharedtest

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MPL-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IgnoredKnownGoroutineLeaks = []goleak.Option{

	goleak.IgnoreTopFunction("github.com/jackc/pgx/v5/pgxpool.(*Pool).backgroundHealthCheck"),

	goleak.IgnoreAnyFunction("github.com/jackc/pgx/v5/pgxpool.(*Pool).triggerHealthCheck.func1"),

	goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"),
}

Functions

func BaseServiceArchetype

func BaseServiceArchetype(tb testing.TB) *baseservice.Archetype

BaseServiceArchetype returns a new base service suitable for use in tests. Returns a new instance so that it's not possible to accidentally taint a shared object.

func DBPool added in v0.20.0

func DBPool(ctx context.Context, tb testing.TB) *pgxpool.Pool

DBPool gets a lazily initialized database pool for `TEST_DATABASE_URL` or `river_test` if the former isn't specified.

func DBPoolClone added in v0.21.0

func DBPoolClone(ctx context.Context, tb testing.TB) *pgxpool.Pool

DBPoolClone returns a disposable clone of DBPool. Share resources by using DBPool when possible, but this is useless for areas like stress tests where context cancellations are likely to end up closing the pool.

Unlike DBPool, adds a test cleanup hook that closes the pool after run.

func DBPoolLibSQL added in v0.24.0

func DBPoolLibSQL(ctx context.Context, tb testing.TB, schema string) *sql.DB

DBPoolLibSQL gets a database pool appropriate for use with libSQL (a SQLite fork) in testing.

func DBPoolSQLite added in v0.23.0

func DBPoolSQLite(ctx context.Context, tb testing.TB, schema string) *sql.DB

DBPoolSQLite gets a database pool appropriate for use with SQLite in testing.

func Logger

func Logger(tb testing.TB) *slog.Logger

Logger returns a logger suitable for use in tests.

Defaults to informational verbosity. If env is set with `RIVER_DEBUG=true`, debug level verbosity is activated.

func LoggerWarn

func LoggerWarn(tb testutil.TestingTB) *slog.Logger

LoggerWarn returns a logger suitable for use in tests which outputs only at warn or above. Useful in tests where particularly noisy log output is expected.

func TestDatabaseURL added in v0.21.0

func TestDatabaseURL() string

TestDatabaseURL returns `TEST_DATABASE_URL` or a default URL pointing to `river_test` and with suitable connection configuration defaults.

func WaitOrTimeout

func WaitOrTimeout[T any](tb testing.TB, waitChan <-chan T) T

WaitOrTimeout tries to wait on the given channel for a value to come through, and returns it if one does, but times out after a reasonable amount of time. Useful to guarantee that test cases don't hang forever, even in the event of something wrong.

func WaitOrTimeoutN

func WaitOrTimeoutN[T any](tb testutil.TestingTB, waitChan <-chan T, numValues int) []T

WaitOrTimeoutN tries to wait on the given channel for N values to come through, and returns it if they do, but times out after a reasonable amount of time. Useful to guarantee that test cases don't hang forever, even in the event of something wrong.

func WaitTimeout

func WaitTimeout() time.Duration

WaitTimeout returns a duration broadly appropriate for waiting on an expected event in a test, and which is used for `TestSignal.WaitOrTimeout` in the main package and `WaitOrTimeout` above. Its main purpose is to allow a little extra leeway in GitHub Actions where we occasionally seem to observe subpar performance which leads to timeouts and test intermittency, while still keeping a tight a timeout for local test runs where this is never a problem.

func WrapTestMain

func WrapTestMain(m *testing.M)

WrapTestMain performs some common setup and teardown that should be shared amongst all packages. e.g. Configures a manager for test databases on setup, and checks for no goroutine leaks on teardown.

Types

type TimeStub

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

TimeStub implements baseservice.TimeGeneratorWithStub to allow time to be stubbed in tests.

It exists separately from rivertest.TimeStub to avoid a circular dependency.

func (*TimeStub) NowUTC

func (t *TimeStub) NowUTC() time.Time

func (*TimeStub) NowUTCOrNil

func (t *TimeStub) NowUTCOrNil() *time.Time

func (*TimeStub) StubNowUTC

func (t *TimeStub) StubNowUTC(nowUTC time.Time) time.Time

Jump to

Keyboard shortcuts

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