MCPcopy
hub / github.com/grpc/grpc-go / TestRetryTransparentWhenCommitted

Method TestRetryTransparentWhenCommitted

test/retry_test.go:771–851  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

769}
770
771func (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 {

Callers

nothing calls this directly

Calls 15

HasFiredMethod · 0.95
FireMethod · 0.95
DoneMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
NewEventFunction · 0.92
ErrorFunction · 0.92
MaxConcurrentStreamsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
CodeFunction · 0.92
ErrMethod · 0.80
LogMethod · 0.65

Tested by

no test coverage detected