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

Method TestCZClientSubChannelSocketRegistrationAndDeletion

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

Source from the content-addressed store, hash-verified

362}
363
364func (s) TestCZClientSubChannelSocketRegistrationAndDeletion(t *testing.T) {
365 e := tcpClearRREnv
366 num := 3 // number of backends
367 te := newTest(t, e)
368 var svrAddrs []resolver.Address
369 te.startServers(&testServer{security: e.security}, num)
370 r := manual.NewBuilderWithScheme("whatever")
371 for _, a := range te.srvAddrs {
372 svrAddrs = append(svrAddrs, resolver.Address{Addr: a})
373 }
374 r.InitialState(resolver.State{Addresses: svrAddrs})
375 te.resolverScheme = r.Scheme()
376 te.clientConn(grpc.WithResolvers(r))
377 defer te.tearDown()
378 // Here, we just wait for all sockets to be up. In the future, if we implement
379 // IDLE, we may need to make several rpc calls to create the sockets.
380 if err := verifyResultWithDelay(func() (bool, error) {
381 tcs, _ := channelz.GetTopChannels(0, 0)
382 if len(tcs) != 1 {
383 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
384 }
385 subChans := tcs[0].SubChans()
386 if len(subChans) != num {
387 return false, fmt.Errorf("there should be %d subchannel not %d", num, len(subChans))
388 }
389 count := 0
390 for k := range subChans {
391 sc := channelz.GetSubChannel(k)
392 if sc == nil {
393 return false, fmt.Errorf("got <nil> subchannel")
394 }
395 count += len(sc.Sockets())
396 }
397 if count != num {
398 return false, fmt.Errorf("there should be %d sockets not %d", num, count)
399 }
400
401 return true, nil
402 }); err != nil {
403 t.Fatal(err)
404 }
405
406 r.UpdateState(resolver.State{Addresses: svrAddrs[:len(svrAddrs)-1]})
407
408 if err := verifyResultWithDelay(func() (bool, error) {
409 tcs, _ := channelz.GetTopChannels(0, 0)
410 if len(tcs) != 1 {
411 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
412 }
413 subChans := tcs[0].SubChans()
414 if len(subChans) != num-1 {
415 return false, fmt.Errorf("there should be %d subchannel not %d", num-1, len(subChans))
416 }
417 count := 0
418 for k := range subChans {
419 sc := channelz.GetSubChannel(k)
420 if sc == nil {
421 return false, fmt.Errorf("got <nil> subchannel")

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
GetSubChannelFunction · 0.92
startServersMethod · 0.80
InitialStateMethod · 0.80
SubChansMethod · 0.80
SocketsMethod · 0.80
newTestFunction · 0.70
verifyResultWithDelayFunction · 0.70
SchemeMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected