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

Method TestUpdateStatePauses

balancer/weightedtarget/weightedtarget_test.go:1476–1519  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1474}
1475
1476func (s) TestUpdateStatePauses(t *testing.T) {
1477 cc := &tcc{BalancerClientConn: testutils.NewBalancerClientConn(t)}
1478
1479 balFuncs := stub.BalancerFuncs{
1480 UpdateClientConnState: func(bd *stub.BalancerData, _ balancer.ClientConnState) error {
1481 bd.ClientConn.UpdateState(balancer.State{ConnectivityState: connectivity.TransientFailure, Picker: nil})
1482 bd.ClientConn.UpdateState(balancer.State{ConnectivityState: connectivity.Ready, Picker: nil})
1483 return nil
1484 },
1485 }
1486 stub.Register("update_state_balancer", balFuncs)
1487
1488 wtb := wtbBuilder.Build(cc, balancer.BuildOptions{})
1489 defer wtb.Close()
1490
1491 config, err := wtbParser.ParseConfig([]byte(`
1492{
1493 "targets": {
1494 "cluster_1": {
1495 "weight":1,
1496 "childPolicy": [{"update_state_balancer": ""}]
1497 }
1498 }
1499}`))
1500 if err != nil {
1501 t.Fatalf("failed to parse balancer config: %v", err)
1502 }
1503
1504 // Send the config, and an address with hierarchy path ["cluster_1"].
1505 addrs := []resolver.Address{{Addr: testBackendAddrStrs[0], Attributes: nil}}
1506 if err := wtb.UpdateClientConnState(balancer.ClientConnState{
1507 ResolverState: resolver.State{Endpoints: []resolver.Endpoint{
1508 hierarchy.SetInEndpoint(resolver.Endpoint{Addresses: []resolver.Address{addrs[0]}}, []string{"cds:cluster_1"}),
1509 }},
1510 BalancerConfig: config,
1511 }); err != nil {
1512 t.Fatalf("failed to update ClientConn state: %v", err)
1513 }
1514
1515 // Verify that the only state update is the second one called by the child.
1516 if len(cc.states) != 1 || cc.states[0].ConnectivityState != connectivity.Ready {
1517 t.Fatalf("cc.states = %v; want [connectivity.Ready]", cc.states)
1518 }
1519}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected