testutils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerName = "testService"
	DefaultClientName = "testService-client"
)

Default service names for the test channels.

Variables

This section is empty.

Functions

func CallEcho

func CallEcho(src, target *tchannel.Channel, args *raw.Args) error

CallEcho calls the "echo" endpoint from the given src to target.

func Decrementor

func Decrementor(n int) func() bool

Decrementor returns a function that can be called from multiple goroutines and ensures it will only return true n times.

func DurationArray

func DurationArray(dd ...time.Duration) []time.Duration

DurationArray returns an array with the given durations.

func FrameRelay

func FrameRelay(t *testing.T, destination string, relayFunc func(outgoing bool, f *tchannel.Frame) *tchannel.Frame) (listenHostPort string, cancel func())

FrameRelay sets up a relay that can modify frames using relayFunc.

func GetClosedHostPort

func GetClosedHostPort(t testing.TB) string

GetClosedHostPort will return a host:port that will refuse connections.

func NewClient

func NewClient(t testing.TB, opts *ChannelOpts) *tchannel.Channel

NewClient returns a new TChannel that is not listening.

func NewClientChannel

func NewClientChannel(opts *ChannelOpts) (*tchannel.Channel, error)

NewClientChannel creates a TChannel that is not listening.

func NewIncomingCall

func NewIncomingCall(callerName string) tchannel.IncomingCall

NewIncomingCall creates an incoming call for tests.

func NewServer

func NewServer(t testing.TB, opts *ChannelOpts) *tchannel.Channel

NewServer returns a new TChannel server that listens on :0.

func NewServerChannel

func NewServerChannel(opts *ChannelOpts) (*tchannel.Channel, error)

NewServerChannel creates a TChannel that is listening and returns the channel.

func NowStub

func NowStub(initial time.Time) (stub func() time.Time, increment func(time.Duration))

NowStub returns a stub time.Now function that allows the return values to to be controller by the caller. It returns two functions: stub: The stub time.Now function. increment: Used to control the increment amount between calls.

func Ping

func Ping(src, target *tchannel.Channel) error

Ping sends a ping from src to target.

func RandBytes

func RandBytes(n int) []byte

RandBytes returns n random byte slice that points to a shared random byte array. Since the underlying random array is shared, the returned byte slice must NOT be modified.

func RandString

func RandString(n int) string

RandString returns a random alphanumeric string for testing.

func RegisterEcho

func RegisterEcho(src *tchannel.Channel, f func())

RegisterEcho registers an echo endpoint on the given channel. The optional provided function is run before the handler returns.

func RegisterFunc

func RegisterFunc(ch *tchannel.Channel, name string,
	f func(ctx context.Context, args *raw.Args) (*raw.Res, error))

RegisterFunc registers a function as a handler for the given method name.

func ResetSleepStub

func ResetSleepStub(funcVar *func(time.Duration))

ResetSleepStub resets a Sleep stub.

func RunN

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

RunN runs the given f n times (and passes the run's index) and waits till they complete. It starts n-1 goroutines, and runs one instance in the current goroutine.

func SetTimeout

func SetTimeout(t *testing.T, timeout time.Duration) func()

SetTimeout is used to fail tests after a timeout. It returns a function that should be run once the test is complete. The standard way is to use defer, e.g. defer SetTimeout(t, time.Second)()

func SleepStub

func SleepStub(funcVar *func(time.Duration)) (
	argCh <-chan time.Duration, unblockCh chan<- struct{}, closeFn func())

SleepStub stubs a function variable that points to time.Sleep. It returns two channels to control the sleep stub, and a function to close the channels. Once the stub is closed, any further sleeps will cause panics. The two channels returned are: <-chan time.Duration which will contain arguments that the stub was called with. chan<- struct{} that should be written to when you want the Sleep to return.

func StrArray

func StrArray(ss ...string) []string

StrArray will return an array with the given strings.

func StrMap

func StrMap(ss ...string) map[string]struct{}

StrMap returns a map where the keys are the given strings.

func Timeout

func Timeout(timeout time.Duration) time.Duration

Timeout returns the timeout multiplied by any set multiplier.

func WaitFor

func WaitFor(timeout time.Duration, f func() bool) bool

WaitFor will retry f till it returns true for a maximum of timeout. It returns true if f returned true, false if timeout was hit.

func WaitWG

func WaitWG(wg *sync.WaitGroup, timeout time.Duration) bool

WaitWG waits for the given WaitGroup to be complete with a timeout and returns whether the WaitGroup completed within the timeout.

func WithServer

func WithServer(t testing.TB, opts *ChannelOpts, f func(ch *tchannel.Channel, hostPort string))

WithServer sets up a TChannel that is listening and runs the given function with the channel.

Types

type ChannelOpts

type ChannelOpts struct {
	tchannel.ChannelOptions

	// ServiceName defaults to DefaultServerName or DefaultClientName.
	ServiceName string

	// LogVerification contains options for controlling the log verification.
	LogVerification LogVerification
	// contains filtered or unexported fields
}

ChannelOpts contains options to create a test channel using WithServer

func DefaultOpts

func DefaultOpts(opts *ChannelOpts) *ChannelOpts

DefaultOpts will return opts if opts is non-nil, NewOpts otherwise.

func NewOpts

func NewOpts() *ChannelOpts

NewOpts returns a new ChannelOpts that can be used in a chained fashion.

func (*ChannelOpts) AddLogFilter

func (o *ChannelOpts) AddLogFilter(filter string, maxCount uint) *ChannelOpts

AddLogFilter sets an allowed filter for warning/error logs and sets the maximum number of times that log can occur.

func (*ChannelOpts) DisableLogVerification

func (o *ChannelOpts) DisableLogVerification() *ChannelOpts

DisableLogVerification disables log verification for this channel.

func (*ChannelOpts) SetFramePool

func (o *ChannelOpts) SetFramePool(framePool tchannel.FramePool) *ChannelOpts

SetFramePool sets FramePool in DefaultConnectionOptions.

func (*ChannelOpts) SetProcessName

func (o *ChannelOpts) SetProcessName(processName string) *ChannelOpts

SetProcessName sets the ProcessName in ChannelOptions.

func (*ChannelOpts) SetServiceName

func (o *ChannelOpts) SetServiceName(svcName string) *ChannelOpts

SetServiceName sets ServiceName.

func (*ChannelOpts) SetStatsReporter

func (o *ChannelOpts) SetStatsReporter(statsReporter tchannel.StatsReporter) *ChannelOpts

SetStatsReporter sets StatsReporter in ChannelOptions.

func (*ChannelOpts) SetTimeNow

func (o *ChannelOpts) SetTimeNow(timeNow func() time.Time) *ChannelOpts

SetTimeNow sets TimeNow in ChannelOptions.

func (*ChannelOpts) SetTraceReporter

func (o *ChannelOpts) SetTraceReporter(traceReporter tchannel.TraceReporter) *ChannelOpts

SetTraceReporter sets TraceReporter in ChannelOptions.

func (*ChannelOpts) SetTraceReporterFactory

func (o *ChannelOpts) SetTraceReporterFactory(factory tchannel.TraceReporterFactory) *ChannelOpts

SetTraceReporterFactory sets TraceReporterFactory in ChannelOptions.

func (*ChannelOpts) SetTraceSampleRate

func (o *ChannelOpts) SetTraceSampleRate(sampleRate float64) *ChannelOpts

SetTraceSampleRate sets the TraceSampleRate in ChannelOptions.

type FakeIncomingCall

type FakeIncomingCall struct {
	// CallerNameF is the calling service's name.
	CallerNameF string

	// ShardKeyF is the intended destination for this call.
	ShardKeyF string

	// RemotePeer is the calling service's peer info.
	RemotePeerF tchannel.PeerInfo
}

FakeIncomingCall implements IncomingCall interface. Note: the F suffix for the fields is to clash with the method name.

func (*FakeIncomingCall) CallerName

func (f *FakeIncomingCall) CallerName() string

CallerName returns the caller name as specified in the fake call.

func (*FakeIncomingCall) RemotePeer

func (f *FakeIncomingCall) RemotePeer() tchannel.PeerInfo

RemotePeer returns the caller's peer info.

func (*FakeIncomingCall) ShardKey

func (f *FakeIncomingCall) ShardKey() string

ShardKey returns the shard key as specified in the fake call.

type LogFilter

type LogFilter struct {
	// Filter specifies the substring match to search
	// for in the log message to skip raising an error.
	Filter string

	// Count is the maximum number of allowed warn+ logs matching
	// Filter before errors are raised.
	Count uint
}

LogFilter is a single substring match that can be ignored.

type LogVerification

type LogVerification struct {
	Disabled bool

	Filters []LogFilter
}

LogVerification contains options to control the log verification.

func (*LogVerification) WrapLogger

func (v *LogVerification) WrapLogger(t testing.TB, l tchannel.Logger) tchannel.Logger

WrapLogger wraps the given logger with extra verification.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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