testutil

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package testutil provides shared testing utilities for integration and acceptance tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPUModel

func CPUModel(cpuinfo []byte) string

CPUModel identifies all processor models in Linux cpuinfo, or returns empty for incomplete evidence.

func Consistently

func Consistently(ctx context.Context, window, interval time.Duration, description string, check func(context.Context) error) error

Consistently runs check every interval until window has elapsed and returns its first error at once. The last check runs at the end of the window.

func Poll

func Poll(ctx context.Context, cfg WaitConfig, description string, observe func(context.Context) (PollResult, error)) error

Poll retries only PollPending; PollFailed and cancellation stop immediately.

func VerifyVarnishMemoryResidency

func VerifyVarnishMemoryResidency(values map[string]string) (string, error)

VerifyVarnishMemoryResidency rejects missing evidence or pageable shared-memory mappings.

func WaitForCondition

func WaitForCondition(ctx context.Context, cfg WaitConfig, condition func(context.Context) (bool, error)) error

WaitForCondition polls with exponential backoff until the condition returns true or the timeout is exceeded. The condition function should return (true, nil) when the condition is satisfied, (false, nil) to continue waiting, or (false, error) to record the last error (but continue waiting).

The function checks the condition immediately before waiting, so if the condition is already satisfied, it returns without delay.

func WaitForConditionWithDescription

func WaitForConditionWithDescription(
	ctx context.Context,
	cfg WaitConfig,
	description string,
	condition func(context.Context) (bool, error),
) error

WaitForConditionWithDescription is like WaitForCondition but includes a description in error messages for better debugging. This is the recommended function for most use cases.

Types

type ObservationProbe

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

ObservationProbe samples until Stop and retains the first observation error.

func StartObservationProbe

func StartObservationProbe(ctx context.Context, interval time.Duration, observe func(context.Context) error) (*ObservationProbe, error)

StartObservationProbe requires a successful initial observation before returning.

func (*ObservationProbe) Stop

func (p *ObservationProbe) Stop() error

Stop waits for the in-flight observation and takes a final boundary sample.

type PollResult

type PollResult uint8
const (
	PollPending PollResult = iota
	PollSucceeded
	PollFailed
)

type WaitConfig

type WaitConfig struct {
	// InitialInterval is the starting interval between retry attempts.
	InitialInterval time.Duration

	// MaxInterval is the maximum interval between retry attempts.
	// The backoff will not exceed this value.
	MaxInterval time.Duration

	// Timeout is the total time allowed for the wait operation.
	Timeout time.Duration

	// Multiplier is applied to the interval after each attempt.
	// For example, 2.0 doubles the interval each time.
	Multiplier float64
}

WaitConfig configures wait behavior with exponential backoff.

func DefaultWaitConfig

func DefaultWaitConfig() WaitConfig

DefaultWaitConfig provides sensible defaults for wait operations.

func FastWaitConfig

func FastWaitConfig() WaitConfig

FastWaitConfig is optimized for conditions expected to resolve quickly.

func SlowWaitConfig

func SlowWaitConfig() WaitConfig

SlowWaitConfig is for conditions that may take longer to resolve.

Jump to

Keyboard shortcuts

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