riversharedtest

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

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 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 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.TimeGenerator to allow time to be stubbed in tests.

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