stream_cleanup_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. *
  3. * Copyright 2019 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package test
  19. import (
  20. "context"
  21. "testing"
  22. "google.golang.org/grpc"
  23. "google.golang.org/grpc/codes"
  24. "google.golang.org/grpc/status"
  25. testpb "google.golang.org/grpc/test/grpc_testing"
  26. )
  27. func (s) TestStreamCleanup(t *testing.T) {
  28. const initialWindowSize uint = 70 * 1024 // Must be higher than default 64K, ignored otherwise
  29. const bodySize = 2 * initialWindowSize // Something that is not going to fit in a single window
  30. const callRecvMsgSize uint = 1 // The maximum message size the client can receive
  31. ss := &stubServer{
  32. unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
  33. return &testpb.SimpleResponse{Payload: &testpb.Payload{
  34. Body: make([]byte, bodySize),
  35. }}, nil
  36. },
  37. emptyCall: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
  38. return &testpb.Empty{}, nil
  39. },
  40. }
  41. if err := ss.Start([]grpc.ServerOption{grpc.MaxConcurrentStreams(1)}, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(int(callRecvMsgSize))), grpc.WithInitialWindowSize(int32(initialWindowSize))); err != nil {
  42. t.Fatalf("Error starting endpoint server: %v", err)
  43. }
  44. defer ss.Stop()
  45. if _, err := ss.client.UnaryCall(context.Background(), &testpb.SimpleRequest{}); status.Code(err) != codes.ResourceExhausted {
  46. t.Fatalf("should fail with ResourceExhausted, message's body size: %v, maximum message size the client can receive: %v", bodySize, callRecvMsgSize)
  47. }
  48. if _, err := ss.client.EmptyCall(context.Background(), &testpb.Empty{}); err != nil {
  49. t.Fatalf("should succeed, err: %v", err)
  50. }
  51. }