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

Method TestCZGetChannel

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

Source from the content-addressed store, hash-verified

101}
102
103func (s) TestCZGetChannel(t *testing.T) {
104 e := tcpClearRREnv
105 e.balancer = ""
106 te := newTest(t, e)
107 te.startServer(&testServer{security: e.security})
108 r := manual.NewBuilderWithScheme("whatever")
109 addrs := []resolver.Address{{Addr: te.srvAddr}}
110 r.InitialState(resolver.State{Addresses: addrs})
111 te.resolverScheme = r.Scheme()
112 te.clientConn(grpc.WithResolvers(r))
113 defer te.tearDown()
114 if err := verifyResultWithDelay(func() (bool, error) {
115 tcs, _ := channelz.GetTopChannels(0, 0)
116 if len(tcs) != 1 {
117 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
118 }
119 target := tcs[0].ChannelMetrics.Target.Load()
120 wantTarget := "whatever:///" + te.srvAddr
121 if target == nil || *target != wantTarget {
122 return false, fmt.Errorf("Got channelz target=%v; want %q", target, wantTarget)
123 }
124 state := tcs[0].ChannelMetrics.State.Load()
125 if state == nil || *state != connectivity.Ready {
126 return false, fmt.Errorf("Got channelz state=%v; want %q", state, connectivity.Ready)
127 }
128 return true, nil
129 }); err != nil {
130 t.Fatal(err)
131 }
132}
133
134func (s) TestCZGetSubChannel(t *testing.T) {
135 e := tcpClearRREnv

Callers

nothing calls this directly

Calls 13

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
InitialStateMethod · 0.80
newTestFunction · 0.70
verifyResultWithDelayFunction · 0.70
SchemeMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65
startServerMethod · 0.45
clientConnMethod · 0.45
tearDownMethod · 0.45

Tested by

no test coverage detected