grpchantesting

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 22 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

View Source
var File_grpchantesting_test_proto protoreflect.FileDescriptor
View Source
var TestService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "grpchantesting.TestService",
	HandlerType: (*TestServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Unary",
			Handler:    _TestService_Unary_Handler,
		},
		{
			MethodName: "UseExternalMessageTwice",
			Handler:    _TestService_UseExternalMessageTwice_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "ClientStream",
			Handler:       _TestService_ClientStream_Handler,
			ClientStreams: true,
		},
		{
			StreamName:    "ServerStream",
			Handler:       _TestService_ServerStream_Handler,
			ServerStreams: true,
		},
		{
			StreamName:    "BidiStream",
			Handler:       _TestService_BidiStream_Handler,
			ServerStreams: true,
			ClientStreams: true,
		},
	},
	Metadata: "grpchantesting/test.proto",
}

TestService_ServiceDesc is the grpc.ServiceDesc for TestService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func MetadataNew added in v1.1.0

func MetadataNew(m map[string][]byte) metadata.MD

func RegisterHandlerTestService deprecated

func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)

Deprecated: Use RegisterTestServiceServer instead.

func RegisterTestServiceServer

func RegisterTestServiceServer(s grpc.ServiceRegistrar, srv TestServiceServer)

func RunChannelTestCases

func RunChannelTestCases(t *testing.T, ch grpc.ClientConnInterface, 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][]byte `` /* 155-byte string literal not displayed */
	Trailers     map[string][]byte `` /* 157-byte string literal not displayed */
	ErrorDetails []*anypb.Any      `protobuf:"bytes,7,rep,name=error_details,json=errorDetails,proto3" json:"error_details,omitempty"`
	// contains filtered or unexported fields
}

func (*Message) Descriptor deprecated

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

Deprecated: Use Message.ProtoReflect.Descriptor instead.

func (*Message) GetCode

func (x *Message) GetCode() int32

func (*Message) GetCount

func (x *Message) GetCount() int32

func (*Message) GetDelayMillis

func (x *Message) GetDelayMillis() int32

func (*Message) GetErrorDetails

func (x *Message) GetErrorDetails() []*anypb.Any

func (*Message) GetHeaders

func (x *Message) GetHeaders() map[string][]byte

func (*Message) GetPayload

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

func (*Message) GetTrailers

func (x *Message) GetTrailers() map[string][]byte

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) ProtoReflect added in v1.1.0

func (x *Message) ProtoReflect() protoreflect.Message

func (*Message) Reset

func (x *Message) Reset()

func (*Message) String

func (x *Message) String() string

type TestServer

type TestServer struct {
	UnimplementedTestServiceServer
}

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 *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

TestServiceClient is the client API for TestService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewTestServiceChannelClient deprecated

func NewTestServiceChannelClient(ch grpc.ClientConnInterface) TestServiceClient

Deprecated: Use NewTestServiceClient instead.

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, *emptypb.Empty) (*emptypb.Empty, error)
	// contains filtered or unexported methods
}

TestServiceServer is the server API for TestService service. All implementations must embed UnimplementedTestServiceServer for forward compatibility

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
}

type UnimplementedTestServiceServer added in v1.1.0

type UnimplementedTestServiceServer struct {
}

UnimplementedTestServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedTestServiceServer) BidiStream added in v1.1.0

func (UnimplementedTestServiceServer) ClientStream added in v1.1.0

func (UnimplementedTestServiceServer) ServerStream added in v1.1.0

func (UnimplementedTestServiceServer) Unary added in v1.1.0

func (UnimplementedTestServiceServer) UseExternalMessageTwice added in v1.1.0

type UnsafeTestServiceServer added in v1.1.0

type UnsafeTestServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeTestServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to TestServiceServer will result in compilation errors.

Jump to

Keyboard shortcuts

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