This test is to test the logic in the createTransport after the health check function returns which closes the allowedToReset channel(since it has not been closed inside health check func) to unblock onGoAway/onClose goroutine.
(t *testing.T)
| 608 | // closes the allowedToReset channel(since it has not been closed inside health check func) to unblock |
| 609 | // onGoAway/onClose goroutine. |
| 610 | func (s) TestHealthCheckWithoutSetConnectivityStateCalled(t *testing.T) { |
| 611 | watchFunc := func(_ *testHealthServer, in *healthpb.HealthCheckRequest, stream healthgrpc.Health_WatchServer) error { |
| 612 | if in.Service != "delay" { |
| 613 | return status.Error(codes.FailedPrecondition, |
| 614 | "this special Watch function only handles request with service name to be \"delay\"") |
| 615 | } |
| 616 | // Do nothing to mock a delay of health check response from server side. |
| 617 | // This case is to help with the test that covers the condition that setConnectivityState is not |
| 618 | // called inside HealthCheckFunc before the func returns. |
| 619 | select { |
| 620 | case <-stream.Context().Done(): |
| 621 | case <-time.After(5 * time.Second): |
| 622 | } |
| 623 | return nil |
| 624 | } |
| 625 | s, lis, ts := setupServer(t, watchFunc) |
| 626 | ts.SetServingStatus("delay", healthpb.HealthCheckResponse_SERVING) |
| 627 | |
| 628 | hcEnterChan, hcExitChan := setupHealthCheckWrapper(t) |
| 629 | _, r := setupClient(t, &clientConfig{}) |
| 630 | |
| 631 | // The serviceName "delay" is specially handled at server side, where response will not be sent |
| 632 | // back to client immediately upon receiving the request (client should receive no response until |
| 633 | // test ends). |
| 634 | r.UpdateState(resolver.State{ |
| 635 | Addresses: []resolver.Address{{Addr: lis.Addr().String()}}, |
| 636 | ServiceConfig: parseServiceConfig(t, r, fmt.Sprintf(`{ |
| 637 | "healthCheckConfig": { |
| 638 | "serviceName": "delay" |
| 639 | }, |
| 640 | "loadBalancingConfig": [{"%s":{}}] |
| 641 | }`, roundrobin.Name))}) |
| 642 | |
| 643 | select { |
| 644 | case <-hcExitChan: |
| 645 | t.Fatal("Health check function has exited, which is not expected.") |
| 646 | default: |
| 647 | } |
| 648 | |
| 649 | select { |
| 650 | case <-hcEnterChan: |
| 651 | case <-time.After(5 * time.Second): |
| 652 | t.Fatal("Health check function has not been invoked after 5s.") |
| 653 | } |
| 654 | // trigger transport being closed |
| 655 | s.Stop() |
| 656 | |
| 657 | // The health check func should exit without calling the setConnectivityState func, as server hasn't sent |
| 658 | // any response. |
| 659 | select { |
| 660 | case <-hcExitChan: |
| 661 | case <-time.After(5 * time.Second): |
| 662 | t.Fatal("Health check function has not exited after 5s.") |
| 663 | } |
| 664 | // The deferred leakcheck will check whether there's leaked goroutine, which is an indication |
| 665 | // whether we closes the allowedToReset channel to unblock onGoAway/onClose goroutine. |
| 666 | } |
| 667 |
nothing calls this directly
no test coverage detected