MCPcopy
hub / github.com/grpc/grpc-go / TestHealthCheckChannelzCountingCallFailure

Method TestHealthCheckChannelzCountingCallFailure

test/healthcheck_test.go:816–863  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

814}
815
816func (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.

Callers

nothing calls this directly

Calls 14

ErrorFunction · 0.92
GetTopChannelsFunction · 0.92
GetSubChannelFunction · 0.92
setupServerFunction · 0.85
setupClientFunction · 0.85
SubChansMethod · 0.80
parseServiceConfigFunction · 0.70
verifyResultWithDelayFunction · 0.70
UpdateStateMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected