Help us shape the future of Go! Take the 2026 Go Developer Survey

testwait

package
v0.3.1 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: 2 Imported by: 0

Documentation

Overview

Package testwait bounds test-side waits for asynchronous effects.

A hang guard proves that an effect eventually happens. Its timeout exists only so a genuine hang fails with a named message instead of the binary's -timeout panic, so it must never encode how fast the effect is. Short real-time guards turn scheduler latency on loaded runners (race detector, hosted Windows, CPU contention) into test failures; every guard here waits up to Budget instead.

Product time bounds ("shutdown finishes within 1s") belong in testing/synctest or an inner deadline assertion, never here. Do not call these helpers inside a synctest bubble: the bubble's fake clock would expire the guard as soon as every goroutine is durably blocked. Call them only from the test goroutine, as t.Fatal requires.

Index

Constants

View Source
const MaxBudget = 2 * time.Minute

MaxBudget caps one guard so a hung test still names its wait well before the go test default 10-minute -timeout.

Variables

This section is empty.

Functions

func Budget

func Budget(t testing.TB) time.Duration

Budget returns how long one hang guard may wait: MaxBudget, shortened so the guard expires at least reserve before the test binary's deadline. Once less than reserve+minBudget remains, the budget floors at minBudget, so the reserve is best effort and guards in the binary's last 30 seconds are short.

func Recv

func Recv[T any](t testing.TB, ch <-chan T, what string) T

Recv returns the next value received from ch, or the zero value if ch is closed. It fails the test if neither happens within Budget.

func Until

func Until(t testing.TB, what string, cond func() bool)

Until polls cond until it reports true. It fails the test if cond is still false after Budget. Prefer Recv on a channel the code under test signals; use Until only for state with no notification.

Types

This section is empty.

Jump to

Keyboard shortcuts

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