(t *testing.T)
| 498 | } |
| 499 | |
| 500 | func (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() |
nothing calls this directly
no test coverage detected