testutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testutil provides assertion helpers, deadlock detection and timeout wrappers shared by every bitbox-testkit consumer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEventually

func AssertEventually(t TB, d time.Duration, cond func() bool, msg string)

AssertEventually polls cond at 1ms intervals until it returns true or d elapses. Cheaper than time.Sleep for "did the background work finish".

func MustWithin

func MustWithin(t TB, d time.Duration, fn func())

MustWithin runs fn and fails t if it does not return within d. The check uses a goroutine; deadlocked code is detected at d and the test fails with a stack dump of the runtime.

func MustWithinCtx

func MustWithinCtx(t TB, d time.Duration, fn func(ctx context.Context) error)

MustWithinCtx runs fn(ctx) with a deadline of d. If fn returns an error, t.Fatalf is called.

Types

type Counter

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

Counter is an atomic int64 with test-friendly accessors.

func (*Counter) Add

func (c *Counter) Add(n int64)

func (*Counter) Inc

func (c *Counter) Inc()

func (*Counter) Load

func (c *Counter) Load() int64

func (*Counter) Reset

func (c *Counter) Reset()

type TB

type TB interface {
	Helper()
	Fatalf(format string, args ...any)
}

TB is the minimal subset of testing.TB the helpers need. *testing.T and *testing.B both satisfy it; tests can substitute their own implementation to assert that a helper fails.

Jump to

Keyboard shortcuts

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