(t *testing.T)
| 316 | } |
| 317 | |
| 318 | func (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 | |
| 364 | func (s) TestCZClientSubChannelSocketRegistrationAndDeletion(t *testing.T) { |
| 365 | e := tcpClearRREnv |
nothing calls this directly
no test coverage detected