rivercommon

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxAttempts = 25
	DefaultPriority    = 1
	DefaultQueue       = "default"
)

These constants are made available in rivercommon so that they're accessible by internal packages, but the top-level river package re-exports them, and all user code must use that set instead.

Variables

This section is empty.

Functions

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` and `riverinternaltest.WaitOrTimeout`. It's 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.

Types

type TestSignal

type TestSignal[T any] struct {
	// contains filtered or unexported fields
}

TestSignal is a channel wrapper designed to allow tests to wait on certain events (to test difficult concurrent conditions without intermittency) while also having minimal impact on the production code that calls into it.

Its default value produces a state where its safe to call Signal to signal into it, but where doing so will have no effect. Entities that embed it should by convention provide a TestSignalsInit function that tests can invoke and which calls Init on all member test signals, after which it becomes possible for tests to WaitOrTimeout on them.

func (*TestSignal[T]) Init

func (s *TestSignal[T]) Init()

Init initializes the test signal for use. This should only ever be called from tests.

func (*TestSignal[T]) Signal

func (s *TestSignal[T]) Signal(val T)

Signal signals the test signal. In production where the signal hasn't been initialized, this no ops harmlessly. In tests, the value is written to an internal asynchronous channel which can be waited with WaitOrTimeout.

func (*TestSignal[T]) WaitOrTimeout

func (s *TestSignal[T]) WaitOrTimeout() T

WaitOrTimeout waits on the next value injected by Signal. This should only be used in tests, and can only be used if Init has been invoked on the test signal.

type TestSignalWaiter

type TestSignalWaiter[T any] interface {
	WaitOrTimeout() T
}

TestSignalWaiter provides an interface for TestSignal which only exposes waiting on the signal. This is useful for minimizing functionality across package boundaries.

Jump to

Keyboard shortcuts

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