(t *testing.T)
| 239 | } |
| 240 | |
| 241 | func (s) TestGetServerSockets(t *testing.T) { |
| 242 | svrID := channelz.RegisterServer("") |
| 243 | defer channelz.RemoveEntry(svrID.ID) |
| 244 | refNames := []string{"listen socket 1", "normal socket 1", "normal socket 2"} |
| 245 | ids := make([]int64, 3) |
| 246 | ids[0] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeListen, Parent: svrID, RefName: refNames[0]}).ID |
| 247 | ids[1] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, Parent: svrID, RefName: refNames[1]}).ID |
| 248 | ids[2] = channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, Parent: svrID, RefName: refNames[2]}).ID |
| 249 | for _, id := range ids { |
| 250 | defer channelz.RemoveEntry(id) |
| 251 | } |
| 252 | svr := newCZServer() |
| 253 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 254 | defer cancel() |
| 255 | resp, _ := svr.GetServerSockets(ctx, &channelzpb.GetServerSocketsRequest{ServerId: svrID.ID, StartSocketId: 0}) |
| 256 | if !resp.GetEnd() { |
| 257 | t.Fatalf("resp.GetEnd() want: true, got: %v", resp.GetEnd()) |
| 258 | } |
| 259 | // GetServerSockets only return normal sockets. |
| 260 | want := map[int64]string{ |
| 261 | ids[1]: refNames[1], |
| 262 | ids[2]: refNames[2], |
| 263 | } |
| 264 | if got := convertSocketRefSliceToMap(resp.GetSocketRef()); !cmp.Equal(got, want) { |
| 265 | t.Fatalf("GetServerSockets want: %#v, got: %#v (resp=%v)", want, got, prototext.Format(resp)) |
| 266 | } |
| 267 | |
| 268 | for i := 0; i < 50; i++ { |
| 269 | id := channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, Parent: svrID}) |
| 270 | defer channelz.RemoveEntry(id.ID) |
| 271 | } |
| 272 | resp, _ = svr.GetServerSockets(ctx, &channelzpb.GetServerSocketsRequest{ServerId: svrID.ID, StartSocketId: 0}) |
| 273 | if resp.GetEnd() { |
| 274 | t.Fatalf("resp.GetEnd() want false, got %v", resp.GetEnd()) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // This test makes a GetServerSockets with a non-zero start ID, and expect only |
| 279 | // sockets with ID >= the given start ID. |
nothing calls this directly
no test coverage detected