xtesting

package
v0.0.0-...-b03ede8 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EnvActiveBenchMux = "BENCHMUX_ACTIVE"

EnvActiveBenchMux is the environment variable that controls the active benchmark.

Variables

View Source
var (
	// DefaultTimeout is the default timeout duration for testing.
	// It matches the default value of the -test.timeout flag.
	// See: https://pkg.go.dev/cmd/go#hdr-Testing_flags
	DefaultTimeout = env.Duration("XTESTING_DEFAULT_TIMEOUT", 10*time.Minute)
)

Functions

func CanceledContext

func CanceledContext() context.Context

CanceledContext returns a context that is already canceled. It is useful for testing functions that return a context and expect it to be canceled.

func DeadlineContext

func DeadlineContext(t *testing.T) context.Context

DeadlineContext returns a context with a deadline set based on -test.timeout flag or DefaultTimeout. It also registers a cleanup function to cancel the context when the test finishes.

Types

type BenchMux

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

BenchMux is a benchmark multiplexer that executes a benchmark based on the value set in the EnvActiveBenchMux environment variable.

func NewBenchMux

func NewBenchMux(primary string) *BenchMux

NewBenchMux creates new BenchMux.

func (*BenchMux) Add

func (m *BenchMux) Add(name string, f func(b *testing.B))

Add registers the benchmark function.

func (*BenchMux) AddLoop

func (m *BenchMux) AddLoop(name string, f func(b *testing.B))

AddLoop registers the benchmark function with a loop.

func (*BenchMux) Run

func (m *BenchMux) Run(b *testing.B)

Run executes the selected benchmark. If EnvActiveBenchMux is not set, it executes the primary benchmark.

Jump to

Keyboard shortcuts

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