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

Method TestMaxCallAttempts

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

Source from the content-addressed store, hash-verified

498}
499
500func (s) TestMaxCallAttempts(t *testing.T) {
501 testCases := []struct {
502 serviceMaxAttempts int
503 clientMaxAttempts int
504 expectedAttempts int
505 }{
506 {serviceMaxAttempts: 9, clientMaxAttempts: 4, expectedAttempts: 4},
507 {serviceMaxAttempts: 9, clientMaxAttempts: 7, expectedAttempts: 7},
508 {serviceMaxAttempts: 3, clientMaxAttempts: 10, expectedAttempts: 3},
509 {serviceMaxAttempts: 8, clientMaxAttempts: -1, expectedAttempts: 5}, // 5 is default max
510 {serviceMaxAttempts: 3, clientMaxAttempts: 0, expectedAttempts: 3},
511 }
512
513 for _, tc := range testCases {
514 clientOpts := []grpc.DialOption{
515 grpc.WithMaxCallAttempts(tc.clientMaxAttempts),
516 grpc.WithDefaultServiceConfig(fmt.Sprintf(`{
517 "methodConfig": [{
518 "name": [{"service": "grpc.testing.TestService"}],
519 "waitForReady": true,
520 "retryPolicy": {
521 "MaxAttempts": %d,
522 "InitialBackoff": ".01s",
523 "MaxBackoff": ".01s",
524 "BackoffMultiplier": 1.0,
525 "RetryableStatusCodes": [ "UNAVAILABLE" ]
526 }
527 }]}`, tc.serviceMaxAttempts),
528 ),
529 }
530
531 serverMu := sync.Mutex{}
532 streamCallCount := 0
533 unaryCallCount := 0
534
535 ss := &stubserver.StubServer{
536 FullDuplexCallF: func(testgrpc.TestService_FullDuplexCallServer) error {
537 serverMu.Lock()
538 defer serverMu.Unlock()
539 streamCallCount++
540 return status.New(codes.Unavailable, "this is a test error").Err()
541 },
542 EmptyCallF: func(context.Context, *testpb.Empty) (r *testpb.Empty, err error) {
543 serverMu.Lock()
544 defer serverMu.Unlock()
545 unaryCallCount++
546 return nil, status.New(codes.Unavailable, "this is a test error").Err()
547 },
548 }
549
550 func() {
551
552 if err := ss.Start([]grpc.ServerOption{}, clientOpts...); err != nil {
553 t.Fatalf("Error starting endpoint server: %v", err)
554 }
555 defer ss.Stop()
556 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
557 defer cancel()

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
WithMaxCallAttemptsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NewFunction · 0.92
CodeFunction · 0.92
ErrMethod · 0.80
GetMethodConfigMethod · 0.80
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65
RecvMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected