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

Method TestInitialIdle

balancer/weightedtarget/weightedtarget_test.go:1381–1420  ·  view source on GitHub ↗

TestInitialIdle covers the case that if the child reports Idle, the overall state will be Idle.

(t *testing.T)

Source from the content-addressed store, hash-verified

1379// TestInitialIdle covers the case that if the child reports Idle, the overall
1380// state will be Idle.
1381func (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.

Callers

nothing calls this directly

Calls 8

NewBalancerClientConnFunction · 0.92
SetInEndpointFunction · 0.92
BuildMethod · 0.65
CloseMethod · 0.65
ParseConfigMethod · 0.65
FatalfMethod · 0.65
UpdateClientConnStateMethod · 0.65
UpdateStateMethod · 0.65

Tested by

no test coverage detected