waitForNewSubConns waits for `num` number of subConns to be created. This is expected to be used from tests using the "test_config_balancer" LB policy, which adds an address attribute with value set to the balancer config. Returned value is a map from subBalancer (identified by its config) to subCo
(ctx context.Context, t *testing.T, cc *testutils.BalancerClientConn, num int)
| 1282 | // Returned value is a map from subBalancer (identified by its config) to |
| 1283 | // subConns created by it. |
| 1284 | func waitForNewSubConns(ctx context.Context, t *testing.T, cc *testutils.BalancerClientConn, num int) map[string][]subConnWithAddr { |
| 1285 | t.Helper() |
| 1286 | |
| 1287 | scs := make(map[string][]subConnWithAddr) |
| 1288 | for i := 0; i < num; i++ { |
| 1289 | var addrs []resolver.Address |
| 1290 | select { |
| 1291 | case <-ctx.Done(): |
| 1292 | t.Fatalf("Timed out waiting for addresses for new SubConn.") |
| 1293 | case addrs = <-cc.NewSubConnAddrsCh: |
| 1294 | } |
| 1295 | if len(addrs) != 1 { |
| 1296 | t.Fatalf("received subConns with %d addresses, want 1", len(addrs)) |
| 1297 | } |
| 1298 | cfg, ok := getConfigKey(addrs[0].Attributes) |
| 1299 | if !ok { |
| 1300 | t.Fatalf("received subConn address %v contains no attribute for balancer config", addrs[0]) |
| 1301 | } |
| 1302 | var sc balancer.SubConn |
| 1303 | select { |
| 1304 | case <-ctx.Done(): |
| 1305 | t.Fatalf("Timed out waiting for new SubConn.") |
| 1306 | case sc = <-cc.NewSubConnCh: |
| 1307 | } |
| 1308 | scWithAddr := subConnWithAddr{sc: sc, addr: addrs[0]} |
| 1309 | scs[cfg] = append(scs[cfg], scWithAddr) |
| 1310 | } |
| 1311 | return scs |
| 1312 | } |
| 1313 | |
| 1314 | func verifySubConnAddrs(t *testing.T, scs map[string][]subConnWithAddr, wantSubConnAddrs map[string][]resolver.Address) { |
| 1315 | t.Helper() |
no test coverage detected