testsignal

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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(tb testutil.TestingTB)

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

func (*TestSignal[T]) RequireEmpty added in v0.23.0

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

RequireEmpty requires that the test signal be empty (i.e. have not received any values).

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]) WaitC

func (s TestSignal[T]) WaitC() <-chan T

WaitC returns a channel on which a value from the test signal can be waited upon.

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