test

package
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package test provides helpers to test the various pion transports implementations. The tests are standardized around the io.ReadWriteCloser interface. This package is meant to be used in addition to golang.org/x/net/nettest.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRoutines

func CheckRoutines(t *testing.T) func()

CheckRoutines is used to check for leaked go-routines

func CheckRoutinesStrict added in v3.0.3

func CheckRoutinesStrict(tb testing.TB) func()

CheckRoutinesStrict is used to check for leaked go-routines. It differs from CheckRoutines in that it has very little tolerance for lingering goroutines. This is helpful for tests that need to ensure clean closure of resources. Checking the state of goroutines exactly is tricky. As users writing goroutines, we tend to clean up gracefully using some synchronization pattern. When used correctly, we won't leak goroutines, but we cannot gurantee *when* the goroutines will end. This is the nature of waiting on the runtime's goexit1 being called which is the final subroutine called, which is after any user written code. This small, but possible chance to have a thread (not goroutine) be preempted before this is called, can have our goroutine stack be not quite correct yet. The best we can do is sleep a little bit and try to encourage the runtime to run that goroutine (G) on the machine (M) it belongs to.

func FlattenErrs

func FlattenErrs(errs []error) error

FlattenErrs flattens a slice of errors into a single error

func GatherErrs

func GatherErrs(c chan error) []error

GatherErrs gathers all errors returned by a channel. It blocks until the channel is closed.

func Stress

func Stress(ca io.Writer, cb io.Reader, opt Options) error

Stress enables stress testing of a io.ReadWriter. It checks that packets are received correctly and in order.

func StressContext

func StressContext(ctx context.Context, ca netctx.Writer, cb netctx.Reader, opt Options) error

StressContext enables stress testing of a io.ReadWriter. It checks that packets are received correctly and in order.

func StressDuplex

func StressDuplex(ca io.ReadWriter, cb io.ReadWriter, opt Options) error

StressDuplex enables duplex stress testing of a io.ReadWriter. It checks that packets are received correctly and in order.

func StressDuplexContext

func StressDuplexContext(ctx context.Context, ca netctx.ReadWriter, cb netctx.ReadWriter, opt Options) error

StressDuplexContext enables duplex stress testing of a io.ReadWriter. It checks that packets are received correctly and in order.

func TimeOut

func TimeOut(t time.Duration) *time.Timer

TimeOut is used to panic if a test takes to long. It will print the current goroutines and panic. It is meant as an aid in debugging deadlocks.

Types

type Bridge

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

Bridge represents a network between the two endpoints.

func NewBridge

func NewBridge() *Bridge

NewBridge creates a new bridge with two endpoints.

func (*Bridge) Drop

func (br *Bridge) Drop(fromID, offset, n int)

Drop drops the specified number of packets from the given offset index of the specified queue.

func (*Bridge) DropNextNWrites

func (br *Bridge) DropNextNWrites(fromID, n int)

DropNextNWrites drops the next n packets that will be written to the specified queue.

func (*Bridge) Filter

func (br *Bridge) Filter(fromID int, cb func([]byte) bool)

Filter filters (drops) packets based on return value of the given callback.

func (*Bridge) GetConn0

func (br *Bridge) GetConn0() net.Conn

GetConn0 returns an endpoint of the bridge, conn0.

func (*Bridge) GetConn1

func (br *Bridge) GetConn1() net.Conn

GetConn1 returns an endpoint of the bridge, conn1.

func (*Bridge) Len

func (br *Bridge) Len(fromID int) int

Len returns number of queued packets.

func (*Bridge) Process

func (br *Bridge) Process()

Process repeats tick() calls until no more outstanding packet in the queues.

func (*Bridge) Push

func (br *Bridge) Push(packet []byte, fromID int) bool

Push pushes a packet into the specified queue.

func (*Bridge) Reorder

func (br *Bridge) Reorder(fromID int) error

Reorder inverses the order of packets currently in the specified queue.

func (*Bridge) ReorderNextNWrites

func (br *Bridge) ReorderNextNWrites(fromID, n int)

ReorderNextNWrites drops the next n packets that will be written to the specified queue.

func (*Bridge) SetLossChance

func (br *Bridge) SetLossChance(chance int) error

SetLossChance sets the probability of writes being discard (to introduce artificial loss)

func (*Bridge) Tick

func (br *Bridge) Tick() int

Tick attempts to hand a packet from the queue for each directions, to readers, if there are waiting on the queue. If there's no reader, it will return immediately.

type Options

type Options struct {
	MsgSize  int
	MsgCount int
}

Options represents the configuration of the stress test

Jump to

Keyboard shortcuts

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