TestInitialIdle covers the case that if the child reports Idle, the overall state will be Idle.
(t *testing.T)
| 1379 | // TestInitialIdle covers the case that if the child reports Idle, the overall |
| 1380 | // state will be Idle. |
| 1381 | func (s) TestInitialIdle(t *testing.T) { |
| 1382 | cc := testutils.NewBalancerClientConn(t) |
| 1383 | wtb := wtbBuilder.Build(cc, balancer.BuildOptions{}) |
| 1384 | defer wtb.Close() |
| 1385 | |
| 1386 | config, err := wtbParser.ParseConfig([]byte(` |
| 1387 | { |
| 1388 | "targets": { |
| 1389 | "cluster_1": { |
| 1390 | "weight":1, |
| 1391 | "childPolicy": [{"test-init-idle-balancer": ""}] |
| 1392 | } |
| 1393 | } |
| 1394 | }`)) |
| 1395 | if err != nil { |
| 1396 | t.Fatalf("failed to parse balancer config: %v", err) |
| 1397 | } |
| 1398 | |
| 1399 | // Send the config, and an address with hierarchy path ["cluster_1"]. |
| 1400 | addrs := []resolver.Address{{Addr: testBackendAddrStrs[0], Attributes: nil}} |
| 1401 | if err := wtb.UpdateClientConnState(balancer.ClientConnState{ |
| 1402 | ResolverState: resolver.State{Endpoints: []resolver.Endpoint{ |
| 1403 | hierarchy.SetInEndpoint(resolver.Endpoint{Addresses: []resolver.Address{addrs[0]}}, []string{"cds:cluster_1"}), |
| 1404 | }}, |
| 1405 | BalancerConfig: config, |
| 1406 | }); err != nil { |
| 1407 | t.Fatalf("failed to update ClientConn state: %v", err) |
| 1408 | } |
| 1409 | |
| 1410 | // Verify that a subconn is created with the address, and the hierarchy path |
| 1411 | // in the address is cleared. |
| 1412 | for range addrs { |
| 1413 | sc := <-cc.NewSubConnCh |
| 1414 | sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Idle}) |
| 1415 | } |
| 1416 | |
| 1417 | if state := <-cc.NewStateCh; state != connectivity.Idle { |
| 1418 | t.Fatalf("Received aggregated state: %v, want Idle", state) |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | // TestIgnoreSubBalancerStateTransitions covers the case that if the child reports a |
| 1423 | // transition from TF to Connecting, the overall state will still be TF. |
nothing calls this directly
no test coverage detected