Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

58 lignes
2.1 KiB

  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. }