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

Method TestCZChannelAddressResolutionChange

test/channelz_test.go:1672–1778  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1670}
1671
1672func (s) TestCZChannelAddressResolutionChange(t *testing.T) {
1673 e := tcpClearRREnv
1674 e.balancer = ""
1675 te := newTest(t, e)
1676 te.startServer(&testServer{security: e.security})
1677 r := manual.NewBuilderWithScheme("whatever")
1678 addrs := []resolver.Address{{Addr: te.srvAddr}}
1679 r.InitialState(resolver.State{Addresses: addrs})
1680 te.resolverScheme = r.Scheme()
1681 te.clientConn(grpc.WithResolvers(r))
1682 defer te.tearDown()
1683 var cid int64
1684 // Here, we just wait for all sockets to be up. In the future, if we implement
1685 // IDLE, we may need to make several rpc calls to create the sockets.
1686 if err := verifyResultWithDelay(func() (bool, error) {
1687 tcs, _ := channelz.GetTopChannels(0, 0)
1688 if len(tcs) != 1 {
1689 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
1690 }
1691 cid = tcs[0].ID
1692 trace := tcs[0].Trace()
1693 for i := len(trace.Events) - 1; i >= 0; i-- {
1694 if strings.Contains(trace.Events[i].Desc, "resolver returned new addresses") {
1695 break
1696 }
1697 if i == 0 {
1698 return false, fmt.Errorf("events do not contain expected address resolution from empty address state. Got: %+v", trace.Events)
1699 }
1700 }
1701 return true, nil
1702 }); err != nil {
1703 t.Fatal(err)
1704 }
1705 r.UpdateState(resolver.State{
1706 Addresses: addrs,
1707 ServiceConfig: parseServiceConfig(t, r, `{"loadBalancingPolicy": "round_robin"}`),
1708 })
1709
1710 if err := verifyResultWithDelay(func() (bool, error) {
1711 cm := channelz.GetChannel(cid)
1712 trace := cm.Trace()
1713 for i := len(trace.Events) - 1; i >= 0; i-- {
1714 if strings.Contains(trace.Events[i].Desc, fmt.Sprintf("Channel switches to new LB policy %q", roundrobin.Name)) {
1715 break
1716 }
1717 if i == 0 {
1718 return false, fmt.Errorf("events do not contain expected address resolution change of LB policy")
1719 }
1720 }
1721 return true, nil
1722 }); err != nil {
1723 t.Fatal(err)
1724 }
1725
1726 newSC := parseServiceConfig(t, r, `{
1727 "methodConfig": [
1728 {
1729 "name": [

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
GetChannelFunction · 0.92
InitialStateMethod · 0.80
JoinMethod · 0.80
newTestFunction · 0.70
verifyResultWithDelayFunction · 0.70
parseServiceConfigFunction · 0.70
SchemeMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected