grpchantesting

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package grpchantesting helps with testing implementations of alternate gRPC transports. Its main value is in a method that, given a channel, will ensure the channel behaves correctly under various conditions.

It tests successful RPCs, failures, timeouts and client-side cancellations. It also covers all kinds of RPCs: unary, client-streaming, server-streaming and bidirectional-streaming. It can optionally test full-duplex bidi streams if the underlying channel supports that.

The channel must be connected to a server that exposes the test server implementation contained in this package: &grpchantesting.TestServer{}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlerTestService

func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)

func RegisterTestServiceServer

func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer)

func RunChannelTestCases

func RunChannelTestCases(t *testing.T, ch grpchan.Channel, supportsFullDuplex bool)

RunChannelTestCases runs numerous test cases to exercise the behavior of the given channel. The server side of the channel needs to have a *TestServer (in this package) registered to provide the implementation of fsgrpc.TestService (proto in this package). If the channel does not support full-duplex communication, it must provide at least half-duplex support for bidirectional streams.

The test cases will be defined as child tests by invoking t.Run on the given *testing.T.

Types

type Message

type Message struct {
	Payload              []byte            `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
	Count                int32             `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"`
	Code                 int32             `protobuf:"varint,3,opt,name=code,proto3" json:"code,omitempty"`
	DelayMillis          int32             `protobuf:"varint,4,opt,name=delay_millis,json=delayMillis,proto3" json:"delay_millis,omitempty"`
	Headers              map[string]string `` /* 155-byte string literal not displayed */
	Trailers             map[string]string `` /* 157-byte string literal not displayed */
	ErrorDetails         []*any.Any        `protobuf:"bytes,7,rep,name=error_details,json=errorDetails,proto3" json:"error_details,omitempty"`
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func (*Message) Descriptor

func (*Message) Descriptor() ([]byte, []int)

func (*Message) GetCode

func (m *Message) GetCode() int32

func (*Message) GetCount

func (m *Message) GetCount() int32

func (*Message) GetDelayMillis

func (m *Message) GetDelayMillis() int32

func (*Message) GetErrorDetails

func (m *Message) GetErrorDetails() []*any.Any

func (*Message) GetHeaders

func (m *Message) GetHeaders() map[string]string

func (*Message) GetPayload

func (m *Message) GetPayload() []byte

func (*Message) GetTrailers

func (m *Message) GetTrailers() map[string]string

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) String

func (m *Message) String() string

func (*Message) XXX_DiscardUnknown

func (m *Message) XXX_DiscardUnknown()

func (*Message) XXX_Marshal

func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Message) XXX_Merge

func (dst *Message) XXX_Merge(src proto.Message)

func (*Message) XXX_Size

func (m *Message) XXX_Size() int

func (*Message) XXX_Unmarshal

func (m *Message) XXX_Unmarshal(b []byte) error

type TestServer

type TestServer struct{}

TestServer has default responses to the various kinds of methods.

func (*TestServer) BidiStream

func (s *TestServer) BidiStream(str TestService_BidiStreamServer) error

BidiStream implements the TestService server interface.

func (*TestServer) ClientStream

func (s *TestServer) ClientStream(cs TestService_ClientStreamServer) error

ClientStream implements the TestService server interface.

func (*TestServer) ServerStream

func (s *TestServer) ServerStream(req *Message, ss TestService_ServerStreamServer) error

ServerStream implements the TestService server interface.

func (*TestServer) Unary

func (s *TestServer) Unary(ctx context.Context, req *Message) (*Message, error)

Unary implements the TestService server interface.

func (*TestServer) UseExternalMessageTwice

func (s *TestServer) UseExternalMessageTwice(ctx context.Context, in *empty.Empty) (*empty.Empty, error)

UseExternalMessageTwice implements the TestService server interface.

type TestServiceClient

type TestServiceClient interface {
	Unary(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error)
	ClientStream(ctx context.Context, opts ...grpc.CallOption) (TestService_ClientStreamClient, error)
	ServerStream(ctx context.Context, in *Message, opts ...grpc.CallOption) (TestService_ServerStreamClient, error)
	BidiStream(ctx context.Context, opts ...grpc.CallOption) (TestService_BidiStreamClient, error)
	// UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in
	UseExternalMessageTwice(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error)
}

TestServiceClient is the client API for TestService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewTestServiceChannelClient

func NewTestServiceChannelClient(ch grpchan.Channel) TestServiceClient

func NewTestServiceClient

func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient

type TestServiceServer

type TestServiceServer interface {
	Unary(context.Context, *Message) (*Message, error)
	ClientStream(TestService_ClientStreamServer) error
	ServerStream(*Message, TestService_ServerStreamServer) error
	BidiStream(TestService_BidiStreamServer) error
	// UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in
	UseExternalMessageTwice(context.Context, *empty.Empty) (*empty.Empty, error)
}

TestServiceServer is the server API for TestService service.

type TestService_BidiStreamClient

type TestService_BidiStreamClient interface {
	Send(*Message) error
	Recv() (*Message, error)
	grpc.ClientStream
}

type TestService_BidiStreamServer

type TestService_BidiStreamServer interface {
	Send(*Message) error
	Recv() (*Message, error)
	grpc.ServerStream
}

type TestService_ClientStreamClient

type TestService_ClientStreamClient interface {
	Send(*Message) error
	CloseAndRecv() (*Message, error)
	grpc.ClientStream
}

type TestService_ClientStreamServer

type TestService_ClientStreamServer interface {
	SendAndClose(*Message) error
	Recv() (*Message, error)
	grpc.ServerStream
}

type TestService_ServerStreamClient

type TestService_ServerStreamClient interface {
	Recv() (*Message, error)
	grpc.ClientStream
}

type TestService_ServerStreamServer

type TestService_ServerStreamServer interface {
	Send(*Message) error
	grpc.ServerStream
}

Jump to

Keyboard shortcuts

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