(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func (s) TestGetTopChannels(t *testing.T) { |
| 103 | tcs := []*channelz.ChannelMetrics{ |
| 104 | channelz.NewChannelMetricForTesting( |
| 105 | connectivity.Connecting, |
| 106 | "test.channelz:1234", |
| 107 | 6, |
| 108 | 2, |
| 109 | 3, |
| 110 | time.Now().UTC().UnixNano(), |
| 111 | ), |
| 112 | channelz.NewChannelMetricForTesting( |
| 113 | connectivity.Connecting, |
| 114 | "test.channelz:1234", |
| 115 | 1, |
| 116 | 2, |
| 117 | 3, |
| 118 | time.Now().UTC().UnixNano(), |
| 119 | ), |
| 120 | channelz.NewChannelMetricForTesting( |
| 121 | connectivity.Shutdown, |
| 122 | "test.channelz:8888", |
| 123 | 0, |
| 124 | 0, |
| 125 | 0, |
| 126 | 0, |
| 127 | ), |
| 128 | } |
| 129 | |
| 130 | for _, c := range tcs { |
| 131 | cz := channelz.RegisterChannel(nil, "test channel") |
| 132 | cz.ChannelMetrics.CopyFrom(c) |
| 133 | defer channelz.RemoveEntry(cz.ID) |
| 134 | } |
| 135 | s := newCZServer() |
| 136 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 137 | defer cancel() |
| 138 | resp, _ := s.GetTopChannels(ctx, &channelzpb.GetTopChannelsRequest{StartChannelId: 0}) |
| 139 | if !resp.GetEnd() { |
| 140 | t.Fatalf("resp.GetEnd() want true, got %v", resp.GetEnd()) |
| 141 | } |
| 142 | for i, c := range resp.GetChannel() { |
| 143 | channel, err := channelProtoToStruct(c) |
| 144 | if err != nil { |
| 145 | t.Fatal(err) |
| 146 | } |
| 147 | if diff := cmp.Diff(tcs[i], channel, protocmp.Transform()); diff != "" { |
| 148 | t.Fatalf("unexpected channel, diff (-want +got):\n%s", diff) |
| 149 | } |
| 150 | } |
| 151 | for i := 0; i < 50; i++ { |
| 152 | cz := channelz.RegisterChannel(nil, "") |
| 153 | defer channelz.RemoveEntry(cz.ID) |
| 154 | } |
| 155 | resp, _ = s.GetTopChannels(ctx, &channelzpb.GetTopChannelsRequest{StartChannelId: 0}) |
| 156 | if resp.GetEnd() { |
| 157 | t.Fatalf("resp.GetEnd() want false, got %v", resp.GetEnd()) |
| 158 | } |
| 159 | } |
nothing calls this directly
no test coverage detected