(t *testing.T)
| 765 | } |
| 766 | |
| 767 | func (s) TestHealthCheckChannelzCountingCallSuccess(t *testing.T) { |
| 768 | watchFunc := func(_ *testHealthServer, in *healthpb.HealthCheckRequest, _ healthgrpc.Health_WatchServer) error { |
| 769 | if in.Service != "channelzSuccess" { |
| 770 | return status.Error(codes.FailedPrecondition, |
| 771 | "this special Watch function only handles request with service name to be \"channelzSuccess\"") |
| 772 | } |
| 773 | return status.Error(codes.OK, "fake success") |
| 774 | } |
| 775 | _, lis, _ := setupServer(t, watchFunc) |
| 776 | |
| 777 | _, r := setupClient(t, nil) |
| 778 | r.UpdateState(resolver.State{ |
| 779 | Addresses: []resolver.Address{{Addr: lis.Addr().String()}}, |
| 780 | ServiceConfig: parseServiceConfig(t, r, fmt.Sprintf(`{ |
| 781 | "healthCheckConfig": { |
| 782 | "serviceName": "channelzSuccess" |
| 783 | }, |
| 784 | "loadBalancingConfig": [{"%s":{}}] |
| 785 | }`, roundrobin.Name))}) |
| 786 | |
| 787 | if err := verifyResultWithDelay(func() (bool, error) { |
| 788 | cm, _ := channelz.GetTopChannels(0, 0) |
| 789 | if len(cm) == 0 { |
| 790 | return false, errors.New("channelz.GetTopChannels return 0 top channel") |
| 791 | } |
| 792 | subChans := cm[0].SubChans() |
| 793 | if len(subChans) == 0 { |
| 794 | return false, errors.New("there is 0 subchannel") |
| 795 | } |
| 796 | var id int64 |
| 797 | for k := range subChans { |
| 798 | id = k |
| 799 | break |
| 800 | } |
| 801 | scm := channelz.GetSubChannel(id) |
| 802 | if scm == nil { |
| 803 | return false, errors.New("nil subchannel returned") |
| 804 | } |
| 805 | // exponential backoff retry may result in more than one health check call. |
| 806 | cstart, csucc, cfail := scm.ChannelMetrics.CallsStarted.Load(), scm.ChannelMetrics.CallsSucceeded.Load(), scm.ChannelMetrics.CallsFailed.Load() |
| 807 | if cstart > 0 && csucc > 0 && cfail == 0 { |
| 808 | return true, nil |
| 809 | } |
| 810 | return false, fmt.Errorf("got %d CallsStarted, %d CallsSucceeded %d CallsFailed, want >0 >0 =0", cstart, csucc, cfail) |
| 811 | }); err != nil { |
| 812 | t.Fatal(err) |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | func (s) TestHealthCheckChannelzCountingCallFailure(t *testing.T) { |
| 817 | watchFunc := func(_ *testHealthServer, in *healthpb.HealthCheckRequest, _ healthgrpc.Health_WatchServer) error { |
nothing calls this directly
no test coverage detected