(t *testing.T)
| 362 | } |
| 363 | |
| 364 | func (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") |
nothing calls this directly
no test coverage detected