Documentation ¶
Index ¶
- Constants
- func CallEcho(src, target *tchannel.Channel, args *raw.Args) error
- func Decrementor(n int) func() bool
- func DurationArray(dd ...time.Duration) []time.Duration
- func FrameRelay(t *testing.T, destination string, ...) (listenHostPort string, cancel func())
- func GetClosedHostPort(t testing.TB) string
- func NewClient(t testing.TB, opts *ChannelOpts) *tchannel.Channel
- func NewClientChannel(opts *ChannelOpts) (*tchannel.Channel, error)
- func NewIncomingCall(callerName string) tchannel.IncomingCall
- func NewServer(t testing.TB, opts *ChannelOpts) *tchannel.Channel
- func NewServerChannel(opts *ChannelOpts) (*tchannel.Channel, error)
- func NowStub(initial time.Time) (stub func() time.Time, increment func(time.Duration))
- func Ping(src, target *tchannel.Channel) error
- func RandBytes(n int) []byte
- func RandString(n int) string
- func RegisterEcho(src *tchannel.Channel, f func())
- func RegisterFunc(ch *tchannel.Channel, name string, ...)
- func ResetSleepStub(funcVar *func(time.Duration))
- func RunN(n int, f func(i int))
- func SetTimeout(t *testing.T, timeout time.Duration) func()
- func SleepStub(funcVar *func(time.Duration)) (argCh <-chan time.Duration, unblockCh chan<- struct{}, closeFn func())
- func StrArray(ss ...string) []string
- func StrMap(ss ...string) map[string]struct{}
- func Timeout(timeout time.Duration) time.Duration
- func WaitFor(timeout time.Duration, f func() bool) bool
- func WaitWG(wg *sync.WaitGroup, timeout time.Duration) bool
- func WithServer(t testing.TB, opts *ChannelOpts, f func(ch *tchannel.Channel, hostPort string))
- type ChannelOpts
- func (o *ChannelOpts) AddLogFilter(filter string, maxCount uint) *ChannelOpts
- func (o *ChannelOpts) DisableLogVerification() *ChannelOpts
- func (o *ChannelOpts) SetFramePool(framePool tchannel.FramePool) *ChannelOpts
- func (o *ChannelOpts) SetProcessName(processName string) *ChannelOpts
- func (o *ChannelOpts) SetServiceName(svcName string) *ChannelOpts
- func (o *ChannelOpts) SetStatsReporter(statsReporter tchannel.StatsReporter) *ChannelOpts
- func (o *ChannelOpts) SetTimeNow(timeNow func() time.Time) *ChannelOpts
- func (o *ChannelOpts) SetTraceReporter(traceReporter tchannel.TraceReporter) *ChannelOpts
- func (o *ChannelOpts) SetTraceReporterFactory(factory tchannel.TraceReporterFactory) *ChannelOpts
- func (o *ChannelOpts) SetTraceSampleRate(sampleRate float64) *ChannelOpts
- type FakeIncomingCall
- type LogFilter
- type LogVerification
Constants ¶
const ( DefaultServerName = "testService" DefaultClientName = "testService-client" )
Default service names for the test channels.
Variables ¶
This section is empty.
Functions ¶
func Decrementor ¶
Decrementor returns a function that can be called from multiple goroutines and ensures it will only return true n times.
func DurationArray ¶
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 ¶
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 ¶
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 RandBytes ¶
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 ¶
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 ¶
ResetSleepStub resets a Sleep stub.
func RunN ¶
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 ¶
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 WaitFor ¶
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 ¶
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 ¶
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.