MCPcopy
hub / github.com/grpc/grpc-go / waitForNewSubConns

Function waitForNewSubConns

balancer/weightedtarget/weightedtarget_test.go:1284–1312  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1282// Returned value is a map from subBalancer (identified by its config) to
1283// subConns created by it.
1284func 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
1314func verifySubConnAddrs(t *testing.T, scs map[string][]subConnWithAddr, wantSubConnAddrs map[string][]resolver.Address) {
1315 t.Helper()

Calls 3

getConfigKeyFunction · 0.85
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected