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

Method TestCZServerMetrics

test/channelz_test.go:691–745  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

689}
690
691func (s) TestCZServerMetrics(t *testing.T) {
692 e := tcpClearRREnv
693 te := newTest(t, e)
694 te.maxServerReceiveMsgSize = newInt(8)
695 te.startServer(&testServer{security: e.security})
696 defer te.tearDown()
697 cc := te.clientConn()
698 tc := testgrpc.NewTestServiceClient(cc)
699 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
700 defer cancel()
701 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
702 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
703 }
704
705 const smallSize = 1
706 const largeSize = 8
707
708 largePayload, err := newPayload(testpb.PayloadType_COMPRESSABLE, largeSize)
709 if err != nil {
710 t.Fatal(err)
711 }
712 req := &testpb.SimpleRequest{
713 ResponseType: testpb.PayloadType_COMPRESSABLE,
714 ResponseSize: int32(smallSize),
715 Payload: largePayload,
716 }
717 if _, err := tc.UnaryCall(ctx, req); err == nil || status.Code(err) != codes.ResourceExhausted {
718 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, error code: %s", err, codes.ResourceExhausted)
719 }
720
721 stream, err := tc.FullDuplexCall(ctx)
722 if err != nil {
723 t.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
724 }
725 defer stream.CloseSend()
726
727 if err := verifyResultWithDelay(func() (bool, error) {
728 ss, _ := channelz.GetServers(0, 0)
729 if len(ss) != 1 {
730 return false, fmt.Errorf("there should only be one server, not %d", len(ss))
731 }
732 if cs := ss[0].ServerMetrics.CallsStarted.Load(); cs != 3 {
733 return false, fmt.Errorf("there should be 3 CallsStarted not %d", cs)
734 }
735 if cs := ss[0].ServerMetrics.CallsSucceeded.Load(); cs != 1 {
736 return false, fmt.Errorf("there should be 1 CallsSucceeded not %d", cs)
737 }
738 if cf := ss[0].ServerMetrics.CallsFailed.Load(); cf != 1 {
739 return false, fmt.Errorf("there should be 1 CallsFailed not %d", cf)
740 }
741 return true, nil
742 }); err != nil {
743 t.Fatal(err)
744 }
745}
746
747type testServiceClientWrapper struct {
748 testgrpc.TestServiceClient

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
FullDuplexCallMethod · 0.95
CodeFunction · 0.92
GetServersFunction · 0.92
newPayloadFunction · 0.85
newTestFunction · 0.70
newIntFunction · 0.70
verifyResultWithDelayFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
CloseSendMethod · 0.65

Tested by

no test coverage detected