Documentation ¶
Index ¶
- Constants
- func CallEcho(src *tchannel.Channel, targetHostPort, targetService string, 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 GetAcceptCloseHostPort(t testing.TB) (string, 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))
- func WithTestServer(t testing.TB, chanOpts *ChannelOpts, f func(*TestServer))
- type ChannelOpts
- func (o *ChannelOpts) AddLogFilter(filter string, maxCount uint, fields ...string) *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
- type TestServer
- func (ts *TestServer) CloseAndVerify()
- func (ts *TestServer) HostPort() string
- func (ts *TestServer) NewClient(opts *ChannelOpts) *tchannel.Channel
- func (ts *TestServer) NewServer(opts *ChannelOpts) *tchannel.Channel
- func (ts *TestServer) Register(h tchannel.Handler, methodName string)
- func (ts *TestServer) Server() *tchannel.Channel
- func (ts *TestServer) ServiceName() string
- func (ts *TestServer) SetVerifyOpts(opts *goroutines.VerifyOpts)
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 GetAcceptCloseHostPort ¶ added in v1.0.5
GetAcceptCloseHostPort returns a host:port that will accept a connection then immediately close it. The returned function can be used to stop the listener.
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.
func WithTestServer ¶ added in v1.0.5
func WithTestServer(t testing.TB, chanOpts *ChannelOpts, f func(*TestServer))
WithTestServer creates a new TestServer, runs the passed function, and then verifies that no resources were leaked.
TODO: run function twice; once with a relay, once without.
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, fields ...string) *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 // RemotePeerF is the calling service's peer info. RemotePeerF tchannel.PeerInfo // RoutingDelegateF is the routing delegate. RoutingDelegateF string }
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) RoutingDelegate ¶ added in v1.0.2
func (f *FakeIncomingCall) RoutingDelegate() string
RoutingDelegate returns the routing delegate as specified in the fake call.
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 // FieldFilters specifies expected substring matches for fields. FieldFilters map[string]string }
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.
type TestServer ¶ added in v1.0.5
A TestServer encapsulates a TChannel server, a client factory, and functions to ensure that we're not leaking resources.
TODO: Include an optional relay.
func NewTestServer ¶ added in v1.0.5
func NewTestServer(t testing.TB, opts *ChannelOpts) *TestServer
NewTestServer constructs a TestServer.
func (*TestServer) CloseAndVerify ¶ added in v1.0.5
func (ts *TestServer) CloseAndVerify()
CloseAndVerify closes all channels verifying each channel as it is closed. It then verifies that no goroutines were leaked.
func (*TestServer) HostPort ¶ added in v1.0.5
func (ts *TestServer) HostPort() string
HostPort returns the host:port for clients to connect to. Note that this may not be the same as the host:port of the server channel.
func (*TestServer) NewClient ¶ added in v1.0.5
func (ts *TestServer) NewClient(opts *ChannelOpts) *tchannel.Channel
NewClient returns a client that with log verification. TODO: Verify message exchanges and leaks for client channels as well.
func (*TestServer) NewServer ¶ added in v1.0.5
func (ts *TestServer) NewServer(opts *ChannelOpts) *tchannel.Channel
NewServer returns a server with log and channel state verification.
func (*TestServer) Register ¶ added in v1.0.5
func (ts *TestServer) Register(h tchannel.Handler, methodName string)
Register registers a handler on the server channel.
func (*TestServer) Server ¶ added in v1.0.5
func (ts *TestServer) Server() *tchannel.Channel
Server returns the underlying TChannel for the server (i.e., the channel on which we're registering handlers).
To support test cases with relays interposed between clients and servers, callers should use the Client(), HostPort(), ServiceName(), and Register() methods instead of accessing the server channel explicitly.
func (*TestServer) ServiceName ¶ added in v1.0.5
func (ts *TestServer) ServiceName() string
ServiceName returns the service name of the server channel.
func (*TestServer) SetVerifyOpts ¶ added in v1.0.5
func (ts *TestServer) SetVerifyOpts(opts *goroutines.VerifyOpts)
SetVerifyOpts specifies the options we'll use during teardown to verify that no goroutines were leaked.