testutil

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SmallDataSize  = 1024        // 1KB
	MediumDataSize = 64 * 1024   // 64KB
	LargeDataSize  = 1024 * 1024 // 1MB
)

Test data sizes

Variables

This section is empty.

Functions

func AssertEventuallyConsistent

func AssertEventuallyConsistent(t *testing.T, condition func() bool, timeout time.Duration, tick time.Duration, msgAndArgs ...interface{})

AssertEventuallyConsistent checks that a condition becomes true within a timeout

func AssertNoError

func AssertNoError(t *testing.T, err error, msgAndArgs ...interface{})

AssertNoError asserts that no error occurred and fails the test if there was

func AssertWithinDuration

func AssertWithinDuration(t *testing.T, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{})

AssertWithinDuration asserts that two times are within a duration of each other

func CreateSimpleTopology

func CreateSimpleTopology(addresses []string, epoch uint64) *clusterpb.ClusterTopology

CreateSimpleTopology creates a basic topology for testing with token assignments

func CreateTopologyWithDownNodes

func CreateTopologyWithDownNodes(addresses []string, downIndices []int, epoch uint64) *clusterpb.ClusterTopology

CreateTopologyWithDownNodes creates a topology with some nodes marked as down

func GenerateTestData

func GenerateTestData(size int) []byte

GenerateTestData generates test data of specified size

func KeyValuePairs

func KeyValuePairs(prefix string, count int) map[string][]byte

KeyValuePairs generates a map of test key-value pairs

func RequireEventuallyConsistent

func RequireEventuallyConsistent(t *testing.T, condition func() bool, timeout time.Duration, tick time.Duration, msgAndArgs ...interface{})

RequireEventuallyConsistent requires that a condition becomes true within a timeout

func RequireNoError

func RequireNoError(t *testing.T, err error, msgAndArgs ...interface{})

RequireNoError requires that no error occurred and fails the test if there was

func RetryWithBackoff

func RetryWithBackoff(ctx context.Context, maxRetries int, initialDelay time.Duration, maxDelay time.Duration, operation func() error) error

RetryWithBackoff retries an operation with exponential backoff

func RunConcurrently

func RunConcurrently(n int, fn func(id int))

RunConcurrently runs a function concurrently n times and waits for completion

func StandardErrorMessages

func StandardErrorMessages() map[string]string

StandardErrorMessages returns common error messages for testing

func StandardTestKeys

func StandardTestKeys() []string

StandardTestKeys returns a set of standard test keys

func WaitForCondition

func WaitForCondition(ctx context.Context, condition func() bool, timeout time.Duration) error

WaitForCondition waits for a condition to become true or returns an error

Types

type ErrorCollector

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

CollectErrors collects errors from concurrent operations

func NewErrorCollector

func NewErrorCollector(bufferSize int) *ErrorCollector

NewErrorCollector creates a new error collector

func (*ErrorCollector) Add

func (ec *ErrorCollector) Add(err error)

Add adds an error to the collector

func (*ErrorCollector) Collect

func (ec *ErrorCollector) Collect() []error

Collect collects all errors and returns them. This method can only be called once - subsequent calls will return the same slice.

func (*ErrorCollector) Count

func (ec *ErrorCollector) Count() int

Count returns the number of errors collected

type FailingReader

type FailingReader struct {
	Data      []byte
	Pos       int
	FailAfter int
}

FailingReader fails after reading a certain amount

func (*FailingReader) Read

func (f *FailingReader) Read(p []byte) (n int, err error)

type SafeBuffer

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

SafeBuffer is a thread-safe buffer for testing

func (*SafeBuffer) Len

func (s *SafeBuffer) Len() int

func (*SafeBuffer) Write

func (s *SafeBuffer) Write(p []byte) (n int, err error)

type SafeReader

type SafeReader struct {
	Data []byte
	// contains filtered or unexported fields
}

SafeReader is a thread-safe reader for testing

func (*SafeReader) Read

func (s *SafeReader) Read(p []byte) (n int, err error)

type TestDataSet

type TestDataSet struct {
	Small  []byte
	Medium []byte
	Large  []byte
}

TestDataSet represents a set of test data with different sizes

func NewTestDataSet

func NewTestDataSet() *TestDataSet

NewTestDataSet creates a new test data set

Jump to

Keyboard shortcuts

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