(t *testing.T)
| 814 | } |
| 815 | |
| 816 | func (s) TestHealthCheckChannelzCountingCallFailure(t *testing.T) { |
| 817 | watchFunc := func(_ *testHealthServer, in *healthpb.HealthCheckRequest, _ healthgrpc.Health_WatchServer) error { |
| 818 | if in.Service != "channelzFailure" { |
| 819 | return status.Error(codes.FailedPrecondition, |
| 820 | "this special Watch function only handles request with service name to be \"channelzFailure\"") |
| 821 | } |
| 822 | return status.Error(codes.Internal, "fake failure") |
| 823 | } |
| 824 | _, lis, _ := setupServer(t, watchFunc) |
| 825 | |
| 826 | _, r := setupClient(t, nil) |
| 827 | r.UpdateState(resolver.State{ |
| 828 | Addresses: []resolver.Address{{Addr: lis.Addr().String()}}, |
| 829 | ServiceConfig: parseServiceConfig(t, r, fmt.Sprintf(`{ |
| 830 | "healthCheckConfig": { |
| 831 | "serviceName": "channelzFailure" |
| 832 | }, |
| 833 | "loadBalancingConfig": [{"%s":{}}] |
| 834 | }`, roundrobin.Name))}) |
| 835 | |
| 836 | if err := verifyResultWithDelay(func() (bool, error) { |
| 837 | cm, _ := channelz.GetTopChannels(0, 0) |
| 838 | if len(cm) == 0 { |
| 839 | return false, errors.New("channelz.GetTopChannels return 0 top channel") |
| 840 | } |
| 841 | subChans := cm[0].SubChans() |
| 842 | if len(subChans) == 0 { |
| 843 | return false, errors.New("there is 0 subchannel") |
| 844 | } |
| 845 | var id int64 |
| 846 | for k := range subChans { |
| 847 | id = k |
| 848 | break |
| 849 | } |
| 850 | scm := channelz.GetSubChannel(id) |
| 851 | if scm == nil { |
| 852 | return false, errors.New("nil subchannel returned") |
| 853 | } |
| 854 | // exponential backoff retry may result in more than one health check call. |
| 855 | cstart, cfail, csucc := scm.ChannelMetrics.CallsStarted.Load(), scm.ChannelMetrics.CallsFailed.Load(), scm.ChannelMetrics.CallsSucceeded.Load() |
| 856 | if cstart > 0 && cfail > 0 && csucc == 0 { |
| 857 | return true, nil |
| 858 | } |
| 859 | return false, fmt.Errorf("got %d CallsStarted, %d CallsFailed, %d CallsSucceeded, want >0, >0", cstart, cfail, csucc) |
| 860 | }); err != nil { |
| 861 | t.Fatal(err) |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | // healthCheck is a helper function to make a unary health check RPC and return |
| 866 | // the response. |
nothing calls this directly
no test coverage detected