rpctest

package
v0.0.0-...-5f226fc Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rpctest holds helpers for development/testing. please check the example of the rpc/rpcpool/wrapper for a real word usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCode

func AssertCode(tb testing.TB, err error, expectedCode rpcstatus.StatusCode) bool

AssertCode asserts that the error returned by an RPC has the expected code.

func AssertStatus

func AssertStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string) bool

AssertStatus asserts that the error returned by an RPC has the expected code and cause.

func AssertStatusContains

func AssertStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string) bool

AssertStatusContains asserts that the error returned by an RPC has the expected code and contains the cause substring.

func ConnectionWithLatency

func ConnectionWithLatency(conn rpcpool.RawConn, duration time.Duration) rpcpool.RawConn

ConnectionWithLatency wraps the original connection and add certain latency to it.

func RequireCode

func RequireCode(tb testing.TB, err error, expectedCode rpcstatus.StatusCode)

RequireCode requires that the error returned by an RPC has the expected code.

func RequireStatus

func RequireStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string)

RequireStatus requires that the error returned by an RPC has the expected code and cause.

func RequireStatusContains

func RequireStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string)

RequireStatusContains requires that the error returned by an RPC has the expected code and contains the cause substring.

Types

type CallRecorder

type CallRecorder struct {
	// contains filtered or unexported fields
}

CallRecorder wraps drpc.Conn and record the rpc names for each calls. It uses an internal Mutex, therefore it's not recommended for production or performance critical operations.

func NewCallRecorder

func NewCallRecorder() CallRecorder

NewCallRecorder returns with a properly initialized RPCounter.

func (*CallRecorder) Attach

func (r *CallRecorder) Attach(conn rpcpool.RawConn) rpcpool.RawConn

Attach wraps a drpc.Conn connection and returns with one where the counters are hooked in.

func (*CallRecorder) CountOf

func (r *CallRecorder) CountOf(rpc string) int

CountOf returns the number of calls to one specific rpc method.

func (*CallRecorder) History

func (r *CallRecorder) History() []string

History returns the list of rpc names which called on this connection.

func (*CallRecorder) RecordCall

func (r *CallRecorder) RecordCall(rpc string)

RecordCall records the fact of one rpc call.

func (*CallRecorder) Reset

func (r *CallRecorder) Reset()

Reset deletes all the existing counters and set everything to 0.

type MessageHandler

type MessageHandler func(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error

MessageHandler is the logic called with the rpc message instead of the original backend.

type MessageHook

type MessageHook func(rpc string, message drpc.Message, err error)

MessageHook is a function which may be called before and after an rpc call.

type MessageInterceptor

type MessageInterceptor struct {
	RequestHook  MessageHook
	ResponseHook MessageHook
	// contains filtered or unexported fields
}

MessageInterceptor is a drpc.Conn which wraps an original connection with more functionality.

func NewMessageInterceptor

func NewMessageInterceptor(conn rpcpool.RawConn) MessageInterceptor

NewMessageInterceptor creates a MessageInterceptor, a connection which delegates all the call to the specific drpc.Conn.

func (*MessageInterceptor) Close

func (l *MessageInterceptor) Close() error

Close closes underlying dprc connection.

func (*MessageInterceptor) Closed

func (l *MessageInterceptor) Closed() <-chan struct{}

Closed returns a channel that is closed if the underlying connection is definitely closed.

func (*MessageInterceptor) Invoke

func (l *MessageInterceptor) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error

Invoke the underlying connection but call the RequestHook/ResponseHook before and after. When the Invoker is set it will be invoked instead of the original connection.

func (*MessageInterceptor) NewStream

func (l *MessageInterceptor) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)

NewStream creates a new wrapped stream.

func (*MessageInterceptor) Transport

func (l *MessageInterceptor) Transport() drpc.Transport

Transport returns the underlying Transport.

func (*MessageInterceptor) Unblocked

func (l *MessageInterceptor) Unblocked() <-chan struct{}

Unblocked returns the unblocked channel from the delegate.

type StubConnection

type StubConnection struct {
	// contains filtered or unexported fields
}

StubConnection can wrap existing drpc.Conn and replaces.

func NewStubConnection

func NewStubConnection() StubConnection

NewStubConnection create a properly initialized StubConnection.

func (*StubConnection) Close

func (s *StubConnection) Close() error

Close simulates the close call (noop).

func (*StubConnection) Closed

func (s *StubConnection) Closed() <-chan struct{}

Closed returns a channel that is closed if the underlying connection is definitely closed.

func (*StubConnection) Invoke

func (s *StubConnection) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error

Invoke the underlying connection but call the RequestHook/ResponseHook before and after. When the Invoker is set it will be invoked instead of the original connection.

func (*StubConnection) NewStream

func (s *StubConnection) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)

NewStream creates a new wrapped stream.

func (*StubConnection) RegisterHandler

func (s *StubConnection) RegisterHandler(rpc string, invoker MessageHandler)

RegisterHandler saves the handler for specific rpc calls.

func (*StubConnection) Transport

func (s *StubConnection) Transport() drpc.Transport

Transport returns a nil transport.

func (*StubConnection) Unblocked

func (s *StubConnection) Unblocked() <-chan struct{}

Unblocked returns a closed channel.

Jump to

Keyboard shortcuts

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