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

Method TestCZChannelTraceCreationDeletion

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

Source from the content-addressed store, hash-verified

1497}
1498
1499func (s) TestCZChannelTraceCreationDeletion(t *testing.T) {
1500 e := tcpClearRREnv
1501 // avoid calling API to set balancer type, which will void service config's change of balancer.
1502 e.balancer = ""
1503 te := newTest(t, e)
1504 r := manual.NewBuilderWithScheme("whatever")
1505 te.resolverScheme = r.Scheme()
1506 te.clientConn(grpc.WithResolvers(r))
1507 resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", ServerName: "grpclb.server"}}
1508 grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`)
1509 r.UpdateState(grpclbstate.Set(resolver.State{ServiceConfig: grpclbConfig}, &grpclbstate.State{BalancerAddresses: resolvedAddrs}))
1510 defer te.tearDown()
1511
1512 var nestedConn int64
1513 if err := verifyResultWithDelay(func() (bool, error) {
1514 tcs, _ := channelz.GetTopChannels(0, 0)
1515 if len(tcs) != 1 {
1516 return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs))
1517 }
1518 nestedChans := tcs[0].NestedChans()
1519 if len(nestedChans) != 1 {
1520 return false, fmt.Errorf("there should be one nested channel from grpclb, not %d", len(nestedChans))
1521 }
1522 for k := range nestedChans {
1523 nestedConn = k
1524 }
1525 trace := tcs[0].Trace()
1526 for _, e := range trace.Events {
1527 if e.RefID == nestedConn && e.RefType != channelz.RefChannel {
1528 return false, fmt.Errorf("nested channel trace event should have RefChannel as RefType")
1529 }
1530 }
1531 ncm := channelz.GetChannel(nestedConn)
1532 ncmTrace := ncm.Trace()
1533 if ncmTrace == nil {
1534 return false, fmt.Errorf("trace for nested channel should not be empty")
1535 }
1536 if len(ncmTrace.Events) == 0 {
1537 return false, fmt.Errorf("there should be at least one trace event for nested channel not 0")
1538 }
1539 pattern := `Channel created`
1540 if ok, _ := regexp.MatchString(pattern, ncmTrace.Events[0].Desc); !ok {
1541 return false, fmt.Errorf("the first trace event should be %q, not %q", pattern, ncmTrace.Events[0].Desc)
1542 }
1543 return true, nil
1544 }); err != nil {
1545 t.Fatal(err)
1546 }
1547
1548 r.UpdateState(resolver.State{
1549 Addresses: []resolver.Address{{Addr: "127.0.0.1:0"}},
1550 ServiceConfig: parseServiceConfig(t, r, `{"loadBalancingPolicy": "round_robin"}`),
1551 })
1552
1553 // wait for the shutdown of grpclb balancer
1554 if err := verifyResultWithDelay(func() (bool, error) {
1555 tcs, _ := channelz.GetTopChannels(0, 0)
1556 if len(tcs) != 1 {

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
GetTopChannelsFunction · 0.92
GetChannelFunction · 0.92
NestedChansMethod · 0.80
newTestFunction · 0.70
parseServiceConfigFunction · 0.70
verifyResultWithDelayFunction · 0.70
SchemeMethod · 0.65
UpdateStateMethod · 0.65
SetMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected