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

Method TestGetServerSocketsNonZeroStartID

channelz/service/service_test.go:280–308  ·  channelz/service/service_test.go::s.TestGetServerSocketsNonZeroStartID

This test makes a GetServerSockets with a non-zero start ID, and expect only sockets with ID >= the given start ID.

(t *testing.T)

Source from the content-addressed store, hash-verified

278// This test makes a GetServerSockets with a non-zero start ID, and expect only
279// sockets with ID >= the given start ID.
280func (s) TestGetServerSocketsNonZeroStartID(t *testing.T) {
281 svrID := channelz.RegisterServer("test server")
282 defer channelz.RemoveEntry(svrID.ID)
283 refNames := []string{"listen socket 1", "normal socket 1", "normal socket 2"}
284 ids := make([]int64, 3)
285 ids[0] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeListen, Parent: svrID, RefName: refNames[0]}).ID
286 ids[1] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, Parent: svrID, RefName: refNames[1]}).ID
287 ids[2] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, Parent: svrID, RefName: refNames[2]}).ID
288 for _, id := range ids {
289 defer channelz.RemoveEntry(id)
290 }
291 svr := newCZServer()
292 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
293 defer cancel()
294 // Make GetServerSockets with startID = ids[1]+1, so socket-1 won't be
295 // included in the response.
296 resp, _ := svr.GetServerSockets(ctx, &channelzpb.GetServerSocketsRequest{ServerId: svrID.ID, StartSocketId: ids[1] + 1})
297 if !resp.GetEnd() {
298 t.Fatalf("resp.GetEnd() want: true, got: %v", resp.GetEnd())
299 }
300 // GetServerSockets only return normal socket-2, socket-1 should be
301 // filtered by start ID.
302 want := map[int64]string{
303 ids[2]: refNames[2],
304 }
305 if !cmp.Equal(convertSocketRefSliceToMap(resp.GetSocketRef()), want) {
306 t.Fatalf("GetServerSockets want: %#v, got: %#v", want, resp.GetSocketRef())
307 }
308}
309
310var logger = grpclog.Component("channelz")
311

Callers

nothing calls this directly

Calls 10

RegisterServerFunction · 0.92
RemoveEntryFunction · 0.92
RegisterSocketFunction · 0.92
newCZServerFunction · 0.85
GetServerSocketsMethod · 0.65
FatalfMethod · 0.65
EqualMethod · 0.65
GetEndMethod · 0.45
GetSocketRefMethod · 0.45

Tested by

no test coverage detected