Documentation ¶
Overview ¶
Package yarpctest provides utilities to test YARPC services and clients.
Index ¶
- func ChooserNop(nop string) func(*FakePeerChooser)
- func ContextWithCall(ctx context.Context, call *Call) context.Context
- func FakePeerChooserPreset() yarpcconfig.PeerChooserPreset
- func FakePeerChooserSpec() yarpcconfig.PeerChooserSpec
- func FakePeerListSpec() yarpcconfig.PeerListSpec
- func FakePeerListUpdaterSpec() yarpcconfig.PeerListUpdaterSpec
- func FakeTransportSpec() yarpcconfig.TransportSpec
- func ListNop(nop string) func(*FakePeerList)
- func NewFakeConfigurator(opts ...yarpcconfig.Option) *yarpcconfig.Configurator
- func UpdaterNop(nop string) func(*FakePeerListUpdater)
- func Watch(u *FakePeerListUpdater)
- type Call
- type FakeOutbound
- func (o *FakeOutbound) Call(ctx context.Context, req *transport.Request) (*transport.Response, error)
- func (o *FakeOutbound) CallOneway(ctx context.Context, req *transport.Request) (transport.Ack, error)
- func (o *FakeOutbound) CallStream(ctx context.Context, streamReq *transport.StreamRequest) (*transport.ClientStream, error)
- func (o *FakeOutbound) Chooser() peer.Chooser
- func (o *FakeOutbound) IsRunning() bool
- func (o *FakeOutbound) NopOption() string
- func (o *FakeOutbound) Start() error
- func (o *FakeOutbound) Stop() error
- func (o *FakeOutbound) TransportName() string
- func (o *FakeOutbound) Transports() []transport.Transport
- type FakeOutboundConfig
- type FakeOutboundOption
- func NopOutboundOption(nopOption string) FakeOutboundOption
- func OutboundCallOnewayOverride(callable OutboundOnewayCallable) FakeOutboundOption
- func OutboundCallOverride(callable OutboundCallable) FakeOutboundOption
- func OutboundCallStreamOverride(callable OutboundStreamCallable) FakeOutboundOption
- func OutboundName(name string) FakeOutboundOption
- func OutboundRouter(router transport.Router) FakeOutboundOption
- type FakePeer
- type FakePeerChooser
- type FakePeerChooserConfig
- type FakePeerChooserOption
- type FakePeerList
- type FakePeerListConfig
- type FakePeerListOption
- type FakePeerListUpdater
- type FakePeerListUpdaterConfig
- type FakePeerListUpdaterOption
- type FakeTransport
- func (t *FakeTransport) Flush()
- func (t *FakeTransport) IsRunning() bool
- func (t *FakeTransport) NewOutbound(c peer.Chooser, opts ...FakeOutboundOption) *FakeOutbound
- func (t *FakeTransport) NopOption() string
- func (t *FakeTransport) Peer(id peer.Identifier) *FakePeer
- func (t *FakeTransport) ReleasePeer(id peer.Identifier, ps peer.Subscriber) error
- func (t *FakeTransport) RetainPeer(id peer.Identifier, ps peer.Subscriber) (peer.Peer, error)
- func (t *FakeTransport) SimulateConnect(id peer.Identifier)
- func (t *FakeTransport) SimulateDisconnect(id peer.Identifier)
- func (t *FakeTransport) SimulateReleaseError(id peer.Identifier, err error)
- func (t *FakeTransport) SimulateRetainError(id peer.Identifier, err error)
- func (t *FakeTransport) SimulateStatusChange(id peer.Identifier, status peer.ConnectionStatus)
- func (t *FakeTransport) Start() error
- func (t *FakeTransport) Stop() error
- type FakeTransportConfig
- type FakeTransportOption
- type ListStressTest
- type ListStressTestReport
- type Logger
- type OutboundCallable
- type OutboundOnewayCallable
- type OutboundStreamCallable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooserNop ¶ added in v1.27.0
func ChooserNop(nop string) func(*FakePeerChooser)
ChooserNop is a fake option for NewFakePeerChooser that sets a nop var. It's fake.
func ContextWithCall ¶ added in v1.45.0
ContextWithCall builds a Context which will yield the provided request metadata when used with yarpc.CallFromContext.
ctx := yarpctest.ContextWithCall(ctx, &Call{..}) handler.GetValue(ctx, &Request{...})
func FakePeerChooserPreset ¶ added in v1.9.0
func FakePeerChooserPreset() yarpcconfig.PeerChooserPreset
FakePeerChooserPreset is a PeerChooserPreset which builds a FakePeerList buind to a FakePeerListUpdater.
func FakePeerChooserSpec ¶ added in v1.27.0
func FakePeerChooserSpec() yarpcconfig.PeerChooserSpec
FakePeerChooserSpec returns a configurator spec for the fake-chooser FakePeerChooser peer selection strategy, suitable for passing to Configurator.MustRegisterPeerChooser.
func FakePeerListSpec ¶ added in v1.9.0
func FakePeerListSpec() yarpcconfig.PeerListSpec
FakePeerListSpec returns a configurator spec for the fake-list FakePeerList peer selection strategy, suitable for passing to Configurator.MustRegisterPeerList.
func FakePeerListUpdaterSpec ¶ added in v1.9.0
func FakePeerListUpdaterSpec() yarpcconfig.PeerListUpdaterSpec
FakePeerListUpdaterSpec returns a configurator spec for the fake-updater FakePeerListUpdater type, suitable for passing to Configurator.MustRegisterPeerListUpdaterSpec.
func FakeTransportSpec ¶ added in v1.9.0
func FakeTransportSpec() yarpcconfig.TransportSpec
FakeTransportSpec returns a configurator spec for the fake-transport transport type, suitable for passing to Configurator.MustRegisterTransport.
func ListNop ¶ added in v1.9.0
func ListNop(nop string) func(*FakePeerList)
ListNop is a fake option for NewFakePeerList that sets a nop var. It's fake.
func NewFakeConfigurator ¶ added in v1.9.0
func NewFakeConfigurator(opts ...yarpcconfig.Option) *yarpcconfig.Configurator
NewFakeConfigurator returns a configurator with fake-transport, fake-peer-list, and fake-peer-list-updater specs already registered, suitable for testing the configurator.
func UpdaterNop ¶ added in v1.9.0
func UpdaterNop(nop string) func(*FakePeerListUpdater)
UpdaterNop is a fake option for NewFakePeerListUpdater that sets a nop var. It's fake.
func Watch ¶ added in v1.9.0
func Watch(u *FakePeerListUpdater)
Watch is a fake option for NewFakePeerListUpdater that enables "watch". It's fake.
Types ¶
type Call ¶ added in v1.45.0
type Call struct { Caller string Service string Transport string Procedure string Encoding transport.Encoding Headers map[string]string ShardKey string RoutingKey string RoutingDelegate string CallerProcedure string // If set, this map will be filled with response headers written to // yarpc.Call. ResponseHeaders map[string]string }
Call specifies metadata for ContextWithCall.
type FakeOutbound ¶ added in v1.9.0
type FakeOutbound struct {
// contains filtered or unexported fields
}
FakeOutbound is a unary outbound for the FakeTransport. It is fake.
func (*FakeOutbound) Call ¶ added in v1.9.0
func (o *FakeOutbound) Call(ctx context.Context, req *transport.Request) (*transport.Response, error)
Call mimicks sending a oneway RPC.
By default, this returns a error. The OutboundCallOverride option supplies an alternate implementation. Alternately, the OutboundRouter option may allow this function to route a unary request to a unary handler.
func (*FakeOutbound) CallOneway ¶ added in v1.27.0
func (o *FakeOutbound) CallOneway(ctx context.Context, req *transport.Request) (transport.Ack, error)
CallOneway mimicks sending a oneway RPC.
By default, this returns an error. The OutboundCallOnewayOverride supplies an alternate implementation. Atlernately, the OutboundRouter options may route the request through to a oneway handler.
func (*FakeOutbound) CallStream ¶ added in v1.27.0
func (o *FakeOutbound) CallStream(ctx context.Context, streamReq *transport.StreamRequest) (*transport.ClientStream, error)
CallStream mimicks sending a streaming RPC.
By default, this returns an error. The OutboundCallStreamOverride option provides a hook to change the behavior. Alternately, the OutboundRouter option may route the request through to a streaming handler.
func (*FakeOutbound) Chooser ¶ added in v1.9.0
func (o *FakeOutbound) Chooser() peer.Chooser
Chooser returns theis FakeOutbound's peer chooser.
func (*FakeOutbound) IsRunning ¶ added in v1.9.0
func (o *FakeOutbound) IsRunning() bool
IsRunning returns whether the fake outbound is running.
func (*FakeOutbound) NopOption ¶ added in v1.9.0
func (o *FakeOutbound) NopOption() string
NopOption returns this FakeOutbound's nopOption. It is fake.
func (*FakeOutbound) Start ¶ added in v1.9.0
func (o *FakeOutbound) Start() error
Start starts the fake outbound and its chooser.
func (*FakeOutbound) Stop ¶ added in v1.9.0
func (o *FakeOutbound) Stop() error
Stop stops the fake outbound and its chooser.
func (*FakeOutbound) TransportName ¶ added in v1.43.0
func (o *FakeOutbound) TransportName() string
TransportName is "fake".
func (*FakeOutbound) Transports ¶ added in v1.9.0
func (o *FakeOutbound) Transports() []transport.Transport
Transports returns the FakeTransport that owns this outbound.
type FakeOutboundConfig ¶ added in v1.9.0
type FakeOutboundConfig struct { yarpcconfig.PeerChooser Nop string `config:"nop,interpolate"` }
FakeOutboundConfig configures the FakeOutbound.
type FakeOutboundOption ¶ added in v1.9.0
type FakeOutboundOption func(*FakeOutbound)
FakeOutboundOption is an option for FakeTransport.NewOutbound.
func NopOutboundOption ¶ added in v1.9.0
func NopOutboundOption(nopOption string) FakeOutboundOption
NopOutboundOption returns an option to set the "nopOption" for a FakeTransport.NewOutbound. The nopOption has no effect exists only to verify that the option was passed, via `FakeOutbound.NopOption()`.
func OutboundCallOnewayOverride ¶ added in v1.43.0
func OutboundCallOnewayOverride(callable OutboundOnewayCallable) FakeOutboundOption
OutboundCallOnewayOverride returns an option to set the "callOverride" for a FakeTransport.NewOutbound.
This can be used to set the functionality for the FakeOutbound's `CallOneway` function.
func OutboundCallOverride ¶ added in v1.9.0
func OutboundCallOverride(callable OutboundCallable) FakeOutboundOption
OutboundCallOverride returns an option to set the "callOverride" for a FakeTransport.NewOutbound. This can be used to set the functionality for the FakeOutbound's `Call` function.
func OutboundCallStreamOverride ¶ added in v1.43.0
func OutboundCallStreamOverride(callable OutboundStreamCallable) FakeOutboundOption
OutboundCallStreamOverride returns an option to set the "callOverride" for a FakeTransport.NewOutbound.
This can be used to set the functionality for the FakeOutbound's `CallStream` function.
func OutboundName ¶ added in v1.43.0
func OutboundName(name string) FakeOutboundOption
OutboundName sets the name of the "fake" outbound.
func OutboundRouter ¶ added in v1.43.0
func OutboundRouter(router transport.Router) FakeOutboundOption
OutboundRouter returns an option to set the router for outbound requests. This connects the outbound to the inbound side of a handler for testing purposes.
type FakePeer ¶ added in v1.8.0
type FakePeer struct {
// contains filtered or unexported fields
}
FakePeer is a fake peer with an identifier.
func (*FakePeer) EndRequest ¶ added in v1.8.0
func (p *FakePeer) EndRequest()
EndRequest decrements pending request count.
func (*FakePeer) Identifier ¶ added in v1.8.0
Identifier returns the fake peer identifier.
func (*FakePeer) StartRequest ¶ added in v1.8.0
func (p *FakePeer) StartRequest()
StartRequest increments pending request count.
type FakePeerChooser ¶ added in v1.27.0
FakePeerChooser is a fake peer chooser.
func NewFakePeerChooser ¶ added in v1.27.0
func NewFakePeerChooser(opts ...FakePeerChooserOption) *FakePeerChooser
NewFakePeerChooser returns a fake peer list.
func (*FakePeerChooser) Choose ¶ added in v1.27.0
func (c *FakePeerChooser) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error)
Choose pretends to choose a peer, but actually always returns an error. It's fake.
func (*FakePeerChooser) Nop ¶ added in v1.27.0
func (c *FakePeerChooser) Nop() string
Nop returns the Peer Chooser's nop variable.
type FakePeerChooserConfig ¶ added in v1.27.0
type FakePeerChooserConfig struct {
Nop string `config:"nop,interpolate"`
}
FakePeerChooserConfig configures the FakePeerChooser.
type FakePeerChooserOption ¶ added in v1.27.0
type FakePeerChooserOption func(*FakePeerChooser)
FakePeerChooserOption is an option for NewFakePeerChooser.
type FakePeerList ¶ added in v1.9.0
FakePeerList is a fake peer list.
func NewFakePeerList ¶ added in v1.9.0
func NewFakePeerList(opts ...FakePeerListOption) *FakePeerList
NewFakePeerList returns a fake peer list.
func (*FakePeerList) Choose ¶ added in v1.9.0
func (c *FakePeerList) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error)
Choose pretends to choose a peer, but actually always returns an error. It's fake.
func (*FakePeerList) Nop ¶ added in v1.9.0
func (c *FakePeerList) Nop() string
Nop returns the Peer List's nop variable.
func (*FakePeerList) Update ¶ added in v1.9.0
func (c *FakePeerList) Update(up peer.ListUpdates) error
Update pretends to add or remove peers.
type FakePeerListConfig ¶ added in v1.9.0
type FakePeerListConfig struct {
Nop string `config:"nop,interpolate"`
}
FakePeerListConfig configures the FakePeerList.
type FakePeerListOption ¶ added in v1.9.0
type FakePeerListOption func(*FakePeerList)
FakePeerListOption is an option for NewFakePeerList.
type FakePeerListUpdater ¶ added in v1.9.0
FakePeerListUpdater is a fake peer list updater. It doesn't actually update a peer list.
func NewFakePeerListUpdater ¶ added in v1.9.0
func NewFakePeerListUpdater(opts ...FakePeerListUpdaterOption) *FakePeerListUpdater
NewFakePeerListUpdater returns a new FakePeerListUpdater, applying any passed options.
func (*FakePeerListUpdater) Nop ¶ added in v1.9.0
func (u *FakePeerListUpdater) Nop() string
Nop returns the nop variable.
func (*FakePeerListUpdater) Watch ¶ added in v1.9.0
func (u *FakePeerListUpdater) Watch() bool
Watch returns whether the peer list updater was configured to "watch". It is fake.
type FakePeerListUpdaterConfig ¶ added in v1.9.0
type FakePeerListUpdaterConfig struct { FakeUpdater string `config:"fake-updater"` Nop string `config:"nop,interpolate"` Watch bool `config:"watch"` }
FakePeerListUpdaterConfig configures a fake-updater FakePeerListUpdater. It has a fake "watch" property that adds the Watch option for NewFakePeerListUpdater when you build a peer list with this config.
type FakePeerListUpdaterOption ¶ added in v1.9.0
type FakePeerListUpdaterOption func(*FakePeerListUpdater)
FakePeerListUpdaterOption is an option for NewFakePeerListUpdater.
type FakeTransport ¶ added in v1.8.0
type FakeTransport struct {
// contains filtered or unexported fields
}
FakeTransport is a fake transport.
func NewFakeTransport ¶ added in v1.8.0
func NewFakeTransport(opts ...FakeTransportOption) *FakeTransport
NewFakeTransport returns a fake transport.
func (*FakeTransport) Flush ¶ added in v1.40.0
func (t *FakeTransport) Flush()
Flush effects all queued status changes from retaining or releasing peers.
Calling RetainPeer and ReleasePeer schedules a peer status change and its notifications. Concrete dialer implementations dispatch these notifications from a goroutine and subscribers may obtain a lock on the peer status. For testability, the fake transport queues these changes and calling Flush dispatches the notifications synchronously, but still off the RetainPeer and ReleasePeer stacks.
func (*FakeTransport) IsRunning ¶ added in v1.40.0
func (t *FakeTransport) IsRunning() bool
IsRunning returns whether the fake transport is running.
func (*FakeTransport) NewOutbound ¶ added in v1.9.0
func (t *FakeTransport) NewOutbound(c peer.Chooser, opts ...FakeOutboundOption) *FakeOutbound
NewOutbound returns a FakeOutbound with a given peer chooser and options.
func (*FakeTransport) NopOption ¶ added in v1.9.0
func (t *FakeTransport) NopOption() string
NopOption returns the configured nopOption. It's fake.
func (*FakeTransport) Peer ¶ added in v1.32.0
func (t *FakeTransport) Peer(id peer.Identifier) *FakePeer
Peer returns the persistent peer object for that peer identifier for the lifetime of the fake transport.
func (*FakeTransport) ReleasePeer ¶ added in v1.8.0
func (t *FakeTransport) ReleasePeer(id peer.Identifier, ps peer.Subscriber) error
ReleasePeer does nothing.
func (*FakeTransport) RetainPeer ¶ added in v1.8.0
func (t *FakeTransport) RetainPeer(id peer.Identifier, ps peer.Subscriber) (peer.Peer, error)
RetainPeer returns a fake peer.
func (*FakeTransport) SimulateConnect ¶ added in v1.32.0
func (t *FakeTransport) SimulateConnect(id peer.Identifier)
SimulateConnect simulates a connection to the peer, marking the peer as available and notifying subscribers.
func (*FakeTransport) SimulateDisconnect ¶ added in v1.32.0
func (t *FakeTransport) SimulateDisconnect(id peer.Identifier)
SimulateDisconnect simulates a disconnection to the peer, marking the peer as unavailable and notifying subscribers.
func (*FakeTransport) SimulateReleaseError ¶ added in v1.40.0
func (t *FakeTransport) SimulateReleaseError(id peer.Identifier, err error)
SimulateReleaseError leaves a note that any subsequent Release for a particular address should return an error.
func (*FakeTransport) SimulateRetainError ¶ added in v1.40.0
func (t *FakeTransport) SimulateRetainError(id peer.Identifier, err error)
SimulateRetainError leaves a note that any subsequent Retain for a particular address should return an error.
func (*FakeTransport) SimulateStatusChange ¶ added in v1.40.0
func (t *FakeTransport) SimulateStatusChange(id peer.Identifier, status peer.ConnectionStatus)
SimulateStatusChange simulates a connection or disconnection to the peer, marking the peer connection status and notifying all subscribers.
func (*FakeTransport) Start ¶ added in v1.40.0
func (t *FakeTransport) Start() error
Start spins up a goroutine to asynchronously flush status change notifications.
If you do not start a fake dialer, you must call Flush explicitly.
func (*FakeTransport) Stop ¶ added in v1.40.0
func (t *FakeTransport) Stop() error
Stop shuts down the fake dialer, allowing its status change notification loop to exit.
type FakeTransportConfig ¶ added in v1.9.0
type FakeTransportConfig struct {
Nop string `config:"nop,interpolate"`
}
FakeTransportConfig configures the FakeTransport.
type FakeTransportOption ¶ added in v1.9.0
type FakeTransportOption func(*FakeTransport)
FakeTransportOption is an option for NewFakeTransport.
func InitialConnectionStatus ¶ added in v1.32.0
func InitialConnectionStatus(s peer.ConnectionStatus) FakeTransportOption
InitialConnectionStatus specifies the initial connection status for new peers of this transport. This is Available by default. With the status set to Unavailable, the test may manual simmulate connection and disconnection with the SimulateConnect and SimulateDisconnect methods.
func NopTransportOption ¶ added in v1.9.0
func NopTransportOption(nopOption string) FakeTransportOption
NopTransportOption returns a no-op option for NewFakeTransport. The option exists to verify that options work.
func ReleaseErrors ¶ added in v1.40.0
func ReleaseErrors(err error, addrs []string) FakeTransportOption
ReleaseErrors specifies an error for ReleasePeer to return for the given addresses.
func RetainErrors ¶ added in v1.40.0
func RetainErrors(err error, addrs []string) FakeTransportOption
RetainErrors specifies an error for RetainPeer to return for the given addresses.
type ListStressTest ¶ added in v1.40.0
type ListStressTest struct { Workers int Duration time.Duration Timeout time.Duration // Latency is the minimum latency of an individual call. // Higher latencies drive up concurrency per worker. Latency time.Duration // LowStress disables membership and connection churn, measuring peer // selection baseline performance without interference. LowStress bool New func(peer.Transport) peer.ChooserList }
ListStressTest describes the parameters of a stress test for a peer list implementation.
func (ListStressTest) Log ¶ added in v1.40.0
func (t ListStressTest) Log(logger Logger)
Log writes the parameters for a stress test.
func (ListStressTest) Run ¶ added in v1.40.0
func (t ListStressTest) Run(logger Logger) *ListStressTestReport
Run runs a stress test on a peer list.
The stress test creates a fake transport and a vector of fake peers. The test concurrently chooses peers from the list with some number of workers while simultaneously adding and removing peers from the peer list and simulating connection and disconnection with those peers.
type ListStressTestReport ¶ added in v1.40.0
type ListStressTestReport struct { Workers int Errors int Choices int Updates int Min time.Duration Max time.Duration Total time.Duration }
ListStressTestReport catalogs the results of a peer list stress test.
Each worker keeps track of its own statistics then sends them through a channel to the test runner. This allows each worker to have independent memory for its log reports and reduces the need for synchronization across threads, which could interfere with the test. The reports get merged into a final report.
func (*ListStressTestReport) Log ¶ added in v1.40.0
func (r *ListStressTestReport) Log(logger Logger)
Log writes the vital statistics for a stress test.
type Logger ¶ added in v1.40.0
type Logger interface {
Logf(format string, args ...interface{})
}
Logger is the interface needed by reports to log results. The testing.T is an example of a logger.
type OutboundCallable ¶ added in v1.9.0
type OutboundCallable func(ctx context.Context, req *transport.Request) (*transport.Response, error)
OutboundCallable is a function that will be called for for an outbound's `Call` method.
type OutboundOnewayCallable ¶ added in v1.43.0
OutboundOnewayCallable is a function that will be called for for an outbound's `Call` method.
type OutboundStreamCallable ¶ added in v1.43.0
type OutboundStreamCallable func(context.Context, *transport.StreamRequest) (*transport.ClientStream, error)
OutboundStreamCallable is a function that will be called for for an outbound's `Call` method.