@@ -131,6 +131,43 @@ func (s) TestCZGetChannel(t *testing.T) {
131
131
}
132
132
}
133
133
134
+ func (s ) TestCZGetSubChannel (t * testing.T ) {
135
+ e := tcpClearRREnv
136
+ e .balancer = ""
137
+ te := newTest (t , e )
138
+ te .startServer (& testServer {security : e .security })
139
+ r := manual .NewBuilderWithScheme ("whatever" )
140
+ addrs := []resolver.Address {{Addr : te .srvAddr }}
141
+ r .InitialState (resolver.State {Addresses : addrs })
142
+ te .resolverScheme = r .Scheme ()
143
+ te .clientConn (grpc .WithResolvers (r ))
144
+ defer te .tearDown ()
145
+ if err := verifyResultWithDelay (func () (bool , error ) {
146
+ tcs , _ := channelz .GetTopChannels (0 , 0 )
147
+ if len (tcs ) != 1 {
148
+ return false , fmt .Errorf ("there should only be one top channel, not %d" , len (tcs ))
149
+ }
150
+ scs := tcs [0 ].SubChans ()
151
+ if len (scs ) != 1 {
152
+ return false , fmt .Errorf ("there should be one subchannel, not %d" , len (scs ))
153
+ }
154
+ var scid int64
155
+ for scid = range scs {
156
+ }
157
+ sc := channelz .GetSubChannel (scid )
158
+ if sc == nil {
159
+ return false , fmt .Errorf ("subchannel with id %v is nil" , scid )
160
+ }
161
+ state := sc .ChannelMetrics .State .Load ()
162
+ if state == nil || * state != connectivity .Ready {
163
+ return false , fmt .Errorf ("Got subchannel state=%v; want %q" , state , connectivity .Ready )
164
+ }
165
+ return true , nil
166
+ }); err != nil {
167
+ t .Fatal (err )
168
+ }
169
+ }
170
+
134
171
func (s ) TestCZGetServer (t * testing.T ) {
135
172
e := tcpClearRREnv
136
173
te := newTest (t , e )
0 commit comments