(t *testing.T)
| 1582 | } |
| 1583 | |
| 1584 | func (s) TestCZSubChannelTraceCreationDeletion(t *testing.T) { |
| 1585 | e := tcpClearRREnv |
| 1586 | te := newTest(t, e) |
| 1587 | te.startServer(&testServer{security: e.security}) |
| 1588 | r := manual.NewBuilderWithScheme("whatever") |
| 1589 | r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: te.srvAddr}}}) |
| 1590 | te.resolverScheme = r.Scheme() |
| 1591 | te.clientConn(grpc.WithResolvers(r)) |
| 1592 | defer te.tearDown() |
| 1593 | var subConn int64 |
| 1594 | // Here, we just wait for all sockets to be up. In the future, if we implement |
| 1595 | // IDLE, we may need to make several rpc calls to create the sockets. |
| 1596 | if err := verifyResultWithDelay(func() (bool, error) { |
| 1597 | tcs, _ := channelz.GetTopChannels(0, 0) |
| 1598 | if len(tcs) != 1 { |
| 1599 | return false, fmt.Errorf("there should only be one top channel, not %d", len(tcs)) |
| 1600 | } |
| 1601 | subChans := tcs[0].SubChans() |
| 1602 | if len(subChans) != 1 { |
| 1603 | return false, fmt.Errorf("there should be 1 subchannel not %d", len(subChans)) |
| 1604 | } |
| 1605 | for k := range subChans { |
| 1606 | subConn = k |
| 1607 | } |
| 1608 | trace := tcs[0].Trace() |
| 1609 | for _, e := range trace.Events { |
| 1610 | if e.RefID == subConn && e.RefType != channelz.RefSubChannel { |
| 1611 | return false, fmt.Errorf("subchannel trace event should have RefType to be RefSubChannel") |
| 1612 | } |
| 1613 | } |
| 1614 | scm := channelz.GetSubChannel(subConn) |
| 1615 | if scm == nil { |
| 1616 | return false, fmt.Errorf("subChannel does not exist") |
| 1617 | } |
| 1618 | scTrace := scm.Trace() |
| 1619 | if scTrace == nil { |
| 1620 | return false, fmt.Errorf("trace for subChannel should not be empty") |
| 1621 | } |
| 1622 | if len(scTrace.Events) == 0 { |
| 1623 | return false, fmt.Errorf("there should be at least one trace event for subChannel not 0") |
| 1624 | } |
| 1625 | pattern := `Subchannel created` |
| 1626 | if ok, _ := regexp.MatchString(pattern, scTrace.Events[0].Desc); !ok { |
| 1627 | return false, fmt.Errorf("the first trace event should be %q, not %q", pattern, scTrace.Events[0].Desc) |
| 1628 | } |
| 1629 | return true, nil |
| 1630 | }); err != nil { |
| 1631 | t.Fatal(err) |
| 1632 | } |
| 1633 | |
| 1634 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 1635 | defer cancel() |
| 1636 | testutils.AwaitState(ctx, t, te.cc, connectivity.Ready) |
| 1637 | r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: "fake address"}}}) |
| 1638 | testutils.AwaitNotState(ctx, t, te.cc, connectivity.Ready) |
| 1639 | |
| 1640 | if err := verifyResultWithDelay(func() (bool, error) { |
| 1641 | tcs, _ := channelz.GetTopChannels(0, 0) |
nothing calls this directly
no test coverage detected