th

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package th provides basic test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoConcurrently

func DoConcurrently(ff ...func())

func DoConcurrentlyN

func DoConcurrentlyN(n int, f func(i int))

func ExpectDrainedChan

func ExpectDrainedChan[A any](t *testing.T, ch <-chan A)

func ExpectError

func ExpectError(t *testing.T, err error, message string)

func ExpectHang added in v0.2.0

func ExpectHang(t *testing.T, waitFor time.Duration, f func())

func ExpectMap added in v0.2.0

func ExpectMap[K, V comparable](t *testing.T, actual map[K]V, expected map[K]V)

func ExpectNeverClosedChan

func ExpectNeverClosedChan[A any](t *testing.T, ch <-chan A, waitFor time.Duration)

func ExpectNoError

func ExpectNoError(t *testing.T, err error)

func ExpectNotHang

func ExpectNotHang(t *testing.T, waitFor time.Duration, f func())

func ExpectNotPanic

func ExpectNotPanic(t *testing.T, f func())

func ExpectSlice

func ExpectSlice[A comparable](t *testing.T, actual []A, expected []A)

func ExpectSorted

func ExpectSorted[T ordered](t *testing.T, arr []T)

func ExpectUnsorted

func ExpectUnsorted[T ordered](t *testing.T, arr []T)

func ExpectValue

func ExpectValue[A comparable](t *testing.T, actual A, expected A)

func ExpectValueGTE

func ExpectValueGTE[A number](t *testing.T, actual A, expected A)

func ExpectValueInDelta

func ExpectValueInDelta[A number](t *testing.T, actual A, expected A, delta A)

func ExpectValueLTE

func ExpectValueLTE[A number](t *testing.T, actual A, expected A)

func FromRange

func FromRange(start, end int) <-chan int

func FromSlice

func FromSlice[A any](slice []A) <-chan A

func Name

func Name(args ...any) string

Name generates a test name. Works the same way as fmt.Sprint, but adds spaces between all arguments.

func Send

func Send[T any](ch chan<- T, items ...T)

func Sort

func Sort[A ordered](s []A)

func TestBothOrderings

func TestBothOrderings(t *testing.T, f func(t *testing.T, ord bool))

func ToSlice

func ToSlice[A any](in <-chan A) []A

Types

type ConcurrencyMonitor added in v0.2.0

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

ConcurrencyMonitor measures the maximum concurrency level reached by goroutines. It enforces maximum possible concurrency by requiring each goroutine to call Inc() at the start and Dec() at the end of its execution. Goroutines calling Inc() are blocked until the concurrency level remains stable for a specified time window, ensuring that concurrency peaks are accurately captured. The highest level of concurrency observed can be retrieved using the Max() method.

func NewConcurrencyMonitor added in v0.2.0

func NewConcurrencyMonitor(window time.Duration) *ConcurrencyMonitor

func (*ConcurrencyMonitor) Dec added in v0.2.0

func (c *ConcurrencyMonitor) Dec()

func (*ConcurrencyMonitor) Inc added in v0.2.0

func (c *ConcurrencyMonitor) Inc()

func (*ConcurrencyMonitor) Max added in v0.2.0

func (c *ConcurrencyMonitor) Max() int

func (*ConcurrencyMonitor) Reset added in v0.2.0

func (c *ConcurrencyMonitor) Reset() int

Jump to

Keyboard shortcuts

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