testutil

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 3 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 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.

func WaitForConditionWithProgress

func WaitForConditionWithProgress(
	ctx context.Context,
	cfg WaitConfig,
	condition func(context.Context) (bool, error),
	onProgress func(attempt int, elapsed time.Duration, lastErr error),
) error

WaitForConditionWithProgress is like WaitForCondition but calls a progress callback on each retry attempt. This is useful for logging progress during long waits.

Types

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