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

Method TestCZChannelMetrics

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

Source from the content-addressed store, hash-verified

600}
601
602func (s) TestCZChannelMetrics(t *testing.T) {
603 e := tcpClearRREnv
604 num := 3 // number of backends
605 te := newTest(t, e)
606 te.maxClientSendMsgSize = newInt(8)
607 var svrAddrs []resolver.Address
608 te.startServers(&testServer{security: e.security}, num)
609 r := manual.NewBuilderWithScheme("whatever")
610 for _, a := range te.srvAddrs {
611 svrAddrs = append(svrAddrs, resolver.Address{Addr: a})
612 }
613 r.InitialState(resolver.State{Addresses: svrAddrs})
614 te.resolverScheme = r.Scheme()
615 cc := te.clientConn(grpc.WithResolvers(r))
616 defer te.tearDown()
617 tc := testgrpc.NewTestServiceClient(cc)
618 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
619 defer cancel()
620 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
621 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
622 }
623
624 const smallSize = 1
625 const largeSize = 8
626
627 largePayload, err := newPayload(testpb.PayloadType_COMPRESSABLE, largeSize)
628 if err != nil {
629 t.Fatal(err)
630 }
631 req := &testpb.SimpleRequest{
632 ResponseType: testpb.PayloadType_COMPRESSABLE,
633 ResponseSize: int32(smallSize),
634 Payload: largePayload,
635 }
636
637 if _, err := tc.UnaryCall(ctx, req); err == nil || status.Code(err) != codes.ResourceExhausted {
638 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, error code: %s", err, codes.ResourceExhausted)
639 }
640
641 stream, err := tc.FullDuplexCall(ctx)
642 if err != nil {
643 t.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
644 }
645 defer stream.CloseSend()
646 // Here, we just wait for all sockets to be up. In the future, if we implement
647 // IDLE, we may need to make several rpc calls to create the sockets.
648 if err := verifyResultWithDelay(func() (bool, error) {
649 tcs, _ := channelz.GetTopChannels(0, 0)
650 if len(tcs) != 1 {
651 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
652 }
653 subChans := tcs[0].SubChans()
654 if len(subChans) != num {
655 return false, fmt.Errorf("there should be %d subchannel not %d", num, len(subChans))
656 }
657 var cst, csu, cf int64
658 for k := range subChans {
659 sc := channelz.GetSubChannel(k)

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
FullDuplexCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
CodeFunction · 0.92
GetTopChannelsFunction · 0.92
GetSubChannelFunction · 0.92
newPayloadFunction · 0.85
startServersMethod · 0.80
InitialStateMethod · 0.80
SubChansMethod · 0.80

Tested by

no test coverage detected