ClientConn close will lead to its addrConns being torn down.
(t *testing.T)
| 493 | |
| 494 | // ClientConn close will lead to its addrConns being torn down. |
| 495 | func (s) TestHealthCheckWithClientConnClose(t *testing.T) { |
| 496 | _, lis, ts := setupServer(t, nil) |
| 497 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVING) |
| 498 | |
| 499 | hcEnterChan, hcExitChan := setupHealthCheckWrapper(t) |
| 500 | cc, r := setupClient(t, &clientConfig{}) |
| 501 | tc := testgrpc.NewTestServiceClient(cc) |
| 502 | r.UpdateState(resolver.State{ |
| 503 | Addresses: []resolver.Address{{Addr: lis.Addr().String()}}, |
| 504 | ServiceConfig: parseServiceConfig(t, r, (fmt.Sprintf(`{ |
| 505 | "healthCheckConfig": { |
| 506 | "serviceName": "foo" |
| 507 | }, |
| 508 | "loadBalancingConfig": [{"%s":{}}] |
| 509 | }`, roundrobin.Name)))}) |
| 510 | |
| 511 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 512 | defer cancel() |
| 513 | // make some rpcs to make sure connection is working. |
| 514 | if err := verifyResultWithDelay(func() (bool, error) { |
| 515 | if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 516 | return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err) |
| 517 | } |
| 518 | return true, nil |
| 519 | }); err != nil { |
| 520 | t.Fatal(err) |
| 521 | } |
| 522 | |
| 523 | select { |
| 524 | case <-hcExitChan: |
| 525 | t.Fatal("Health check function has exited, which is not expected.") |
| 526 | default: |
| 527 | } |
| 528 | |
| 529 | // trigger addrConn teardown |
| 530 | cc.Close() |
| 531 | |
| 532 | select { |
| 533 | case <-hcExitChan: |
| 534 | case <-time.After(5 * time.Second): |
| 535 | select { |
| 536 | case <-hcEnterChan: |
| 537 | default: |
| 538 | t.Fatal("Health check function has not entered after 5s.") |
| 539 | } |
| 540 | t.Fatal("Health check function has not exited after 5s.") |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // This test is to test the logic in the createTransport after the health check function returns which |
| 545 | // closes the skipReset channel(since it has not been closed inside health check func) to unblock |
nothing calls this directly
no test coverage detected