Create a new balancer group, add balancer and backends. - b1, weight 2, backends [0,1] - b2, weight 1, backends [2,3] Start the balancer group and check behavior. Close the balancer group.
(t *testing.T)
| 76 | // |
| 77 | // Close the balancer group. |
| 78 | func (s) TestBalancerGroup_start_close(t *testing.T) { |
| 79 | cc := testutils.NewBalancerClientConn(t) |
| 80 | gator := weightedaggregator.New(cc, nil, testutils.NewTestWRR) |
| 81 | gator.Start() |
| 82 | bg := balancergroup.New(balancergroup.Options{ |
| 83 | CC: cc, |
| 84 | BuildOpts: balancer.BuildOptions{}, |
| 85 | StateAggregator: gator, |
| 86 | Logger: nil, |
| 87 | SubBalancerCloseTimeout: time.Duration(0), |
| 88 | }) |
| 89 | |
| 90 | // Add two balancers to group and send two resolved addresses to both |
| 91 | // balancers. |
| 92 | gator.Add(testBalancerIDs[0], 2) |
| 93 | bg.Add(testBalancerIDs[0], rrBuilder) |
| 94 | bg.UpdateClientConnState(testBalancerIDs[0], balancer.ClientConnState{ResolverState: resolver.State{Endpoints: testBackendEndpoints[0:2]}}) |
| 95 | gator.Add(testBalancerIDs[1], 1) |
| 96 | bg.Add(testBalancerIDs[1], rrBuilder) |
| 97 | bg.UpdateClientConnState(testBalancerIDs[1], balancer.ClientConnState{ResolverState: resolver.State{Endpoints: testBackendEndpoints[2:4]}}) |
| 98 | |
| 99 | m1 := make(map[string]balancer.SubConn) |
| 100 | for i := 0; i < 4; i++ { |
| 101 | addrs := <-cc.NewSubConnAddrsCh |
| 102 | sc := <-cc.NewSubConnCh |
| 103 | m1[addrs[0].Addr] = sc |
| 104 | sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) |
| 105 | sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) |
| 106 | } |
| 107 | |
| 108 | // Test roundrobin on the last picker. |
| 109 | p1 := <-cc.NewPickerCh |
| 110 | want := []balancer.SubConn{ |
| 111 | m1[testBackendAddrs[0].Addr], m1[testBackendAddrs[0].Addr], |
| 112 | m1[testBackendAddrs[1].Addr], m1[testBackendAddrs[1].Addr], |
| 113 | m1[testBackendAddrs[2].Addr], m1[testBackendAddrs[3].Addr], |
| 114 | } |
| 115 | if err := testutils.IsRoundRobin(want, testutils.SubConnFromPicker(p1)); err != nil { |
| 116 | t.Fatalf("want %v, got %v", want, err) |
| 117 | } |
| 118 | |
| 119 | gator.Stop() |
| 120 | bg.Close() |
| 121 | for i := 0; i < 4; i++ { |
| 122 | (<-cc.ShutdownSubConnCh).UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Shutdown}) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Test that balancer group start() doesn't deadlock if the balancer calls back |
| 127 | // into balancer group inline when it gets an update. |
nothing calls this directly
no test coverage detected