This test makes a GetServerSockets with a non-zero start ID, and expect only sockets with ID >= the given start ID.
(t *testing.T)
| 278 | // This test makes a GetServerSockets with a non-zero start ID, and expect only |
| 279 | // sockets with ID >= the given start ID. |
| 280 | func (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 | |
| 310 | var logger = grpclog.Component("channelz") |
| 311 |
nothing calls this directly
no test coverage detected