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

Method TestGetServers

channelz/service/service_test.go:161–239  ·  channelz/service/service_test.go::s.TestGetServers
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func (s) TestGetServers(t *testing.T) {
162 ss := []*channelz.ServerMetrics{
163 channelz.NewServerMetricsForTesting(
164 6,
165 2,
166 3,
167 time.Now().UnixNano(),
168 ),
169 channelz.NewServerMetricsForTesting(
170 1,
171 2,
172 3,
173 time.Now().UnixNano(),
174 ),
175 channelz.NewServerMetricsForTesting(
176 1,
177 0,
178 0,
179 time.Now().UnixNano(),
180 ),
181 }
182
183 firstID := int64(0)
184 for i, s := range ss {
185 svr := channelz.RegisterServer("")
186 if i == 0 {
187 firstID = svr.ID
188 }
189 svr.ServerMetrics.CopyFrom(s)
190 defer channelz.RemoveEntry(svr.ID)
191 }
192 svr := newCZServer()
193 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
194 defer cancel()
195 resp, _ := svr.GetServers(ctx, &channelzpb.GetServersRequest{StartServerId: 0})
196 if !resp.GetEnd() {
197 t.Fatalf("resp.GetEnd() want true, got %v", resp.GetEnd())
198 }
199 serversWant := []*channelzpb.Server{
200 {
201 Ref: &channelzpb.ServerRef{ServerId: firstID, Name: ""},
202 Data: &channelzpb.ServerData{
203 CallsStarted: 6,
204 CallsSucceeded: 2,
205 CallsFailed: 3,
206 LastCallStartedTimestamp: timestamppb.New(time.Unix(0, ss[0].LastCallStartedTimestamp.Load())),
207 },
208 },
209 {
210 Ref: &channelzpb.ServerRef{ServerId: firstID + 1, Name: ""},
211 Data: &channelzpb.ServerData{
212 CallsStarted: 1,
213 CallsSucceeded: 2,
214 CallsFailed: 3,
215 LastCallStartedTimestamp: timestamppb.New(time.Unix(0, ss[1].LastCallStartedTimestamp.Load())),
216 },
217 },
218 {

Callers

nothing calls this directly

Calls 11

RegisterServerFunction · 0.92
RemoveEntryFunction · 0.92
newCZServerFunction · 0.85
NowMethod · 0.80
GetServersMethod · 0.65
FatalfMethod · 0.65
GetServerMethod · 0.65
CopyFromMethod · 0.45
GetEndMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected