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

Method TestCZNestedChannelRegistrationAndDeletion

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

Source from the content-addressed store, hash-verified

316}
317
318func (s) TestCZNestedChannelRegistrationAndDeletion(t *testing.T) {
319 e := tcpClearRREnv
320 // avoid calling API to set balancer type, which will void service config's change of balancer.
321 e.balancer = ""
322 te := newTest(t, e)
323 r := manual.NewBuilderWithScheme("whatever")
324 te.resolverScheme = r.Scheme()
325 te.clientConn(grpc.WithResolvers(r))
326 resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", ServerName: "grpclb.server"}}
327 grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`)
328 r.UpdateState(grpclbstate.Set(resolver.State{ServiceConfig: grpclbConfig}, &grpclbstate.State{BalancerAddresses: resolvedAddrs}))
329 defer te.tearDown()
330
331 if err := verifyResultWithDelay(func() (bool, error) {
332 tcs, _ := channelz.GetTopChannels(0, 0)
333 if len(tcs) != 1 {
334 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
335 }
336 if nestedChans := tcs[0].NestedChans(); len(nestedChans) != 1 {
337 return false, fmt.Errorf("there should be one nested channel from grpclb, not %d", len(nestedChans))
338 }
339 return true, nil
340 }); err != nil {
341 t.Fatal(err)
342 }
343
344 r.UpdateState(resolver.State{
345 Addresses: []resolver.Address{{Addr: "127.0.0.1:0"}},
346 ServiceConfig: parseServiceConfig(t, r, `{"loadBalancingPolicy": "round_robin"}`),
347 })
348
349 // wait for the shutdown of grpclb balancer
350 if err := verifyResultWithDelay(func() (bool, error) {
351 tcs, _ := channelz.GetTopChannels(0, 0)
352 if len(tcs) != 1 {
353 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
354 }
355 if nestedChans := tcs[0].NestedChans(); len(nestedChans) != 0 {
356 return false, fmt.Errorf("there should be 0 nested channel from grpclb, not %d", len(nestedChans))
357 }
358 return true, nil
359 }); err != nil {
360 t.Fatal(err)
361 }
362}
363
364func (s) TestCZClientSubChannelSocketRegistrationAndDeletion(t *testing.T) {
365 e := tcpClearRREnv

Callers

nothing calls this directly

Calls 14

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
NestedChansMethod · 0.80
newTestFunction · 0.70
parseServiceConfigFunction · 0.70
verifyResultWithDelayFunction · 0.70
SchemeMethod · 0.65
UpdateStateMethod · 0.65
SetMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected