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

Method TestHealthCheckChannelzCountingCallSuccess

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

Source from the content-addressed store, hash-verified

765}
766
767func (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
816func (s) TestHealthCheckChannelzCountingCallFailure(t *testing.T) {
817 watchFunc := func(_ *testHealthServer, in *healthpb.HealthCheckRequest, _ healthgrpc.Health_WatchServer) error {

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