riversharedtest

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MPL-2.0 Imports: 15 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"),
}

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 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 testing.TB) *slog.Logger

Logger 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 TestTx added in v0.20.0

func TestTx(ctx context.Context, tb testing.TB) pgx.Tx

TestTx starts a test transaction that's rolled back automatically as the test case is cleaning itself up.

This variant uses the default database pool from DBPool that points to `TEST_DATABASE_URL` or `river_test` if the former wasn't specified.

func TestTxPool added in v0.20.0

func TestTxPool(ctx context.Context, tb testing.TB, dbPool *pgxpool.Pool) pgx.Tx

TestTxPool starts a test transaction that's rolled back automatically as the test case is cleaning itself up.

This variant starts the test transaction on the specified database pool.

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 testing.TB, 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