(t *testing.T)
| 769 | } |
| 770 | |
| 771 | func (s) TestRetryTransparentWhenCommitted(t *testing.T) { |
| 772 | // With MaxConcurrentStreams=1: |
| 773 | // |
| 774 | // 1. Create stream 1 that is retriable. |
| 775 | // 2. Stream 1 is created and fails with a retriable code. |
| 776 | // 3. Create dummy stream 2, blocking indefinitely. |
| 777 | // 4. Stream 1 retries (and blocks until stream 2 finishes) |
| 778 | // 5. Stream 1 is canceled manually. |
| 779 | // |
| 780 | // If there is no bug, the stream is done and errors with CANCELED. With a bug: |
| 781 | // |
| 782 | // 6. Stream 1 has a nil stream (attempt.s). Operations like CloseSend will panic. |
| 783 | |
| 784 | first := grpcsync.NewEvent() |
| 785 | ss := &stubserver.StubServer{ |
| 786 | FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error { |
| 787 | // signal? |
| 788 | if !first.HasFired() { |
| 789 | first.Fire() |
| 790 | t.Log("returned first error") |
| 791 | return status.Error(codes.AlreadyExists, "first attempt fails and is retriable") |
| 792 | } |
| 793 | t.Log("blocking") |
| 794 | <-stream.Context().Done() |
| 795 | return stream.Context().Err() |
| 796 | }, |
| 797 | } |
| 798 | |
| 799 | if err := ss.Start([]grpc.ServerOption{grpc.MaxConcurrentStreams(1)}, |
| 800 | grpc.WithDefaultServiceConfig(`{ |
| 801 | "methodConfig": [{ |
| 802 | "name": [{"service": "grpc.testing.TestService"}], |
| 803 | "waitForReady": true, |
| 804 | "retryPolicy": { |
| 805 | "MaxAttempts": 2, |
| 806 | "InitialBackoff": ".1s", |
| 807 | "MaxBackoff": ".1s", |
| 808 | "BackoffMultiplier": 1.0, |
| 809 | "RetryableStatusCodes": [ "ALREADY_EXISTS" ] |
| 810 | } |
| 811 | }]}`)); err != nil { |
| 812 | t.Fatalf("Error starting endpoint server: %v", err) |
| 813 | } |
| 814 | defer ss.Stop() |
| 815 | |
| 816 | ctx1, cancel1 := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 817 | defer cancel1() |
| 818 | ctx2, cancel2 := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 819 | defer cancel2() |
| 820 | |
| 821 | stream1, err := ss.Client.FullDuplexCall(ctx1) |
| 822 | if err != nil { |
| 823 | t.Fatalf("Error creating stream 1: %v", err) |
| 824 | } |
| 825 | |
| 826 | // Create dummy stream to block indefinitely. |
| 827 | _, err = ss.Client.FullDuplexCall(ctx2) |
| 828 | if err != nil { |
nothing calls this directly
no test coverage detected