test

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 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 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