Skip to content

Commit

Permalink
fix count of rooms with deletion priority
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-yankabuki committed Feb 14, 2023
1 parent 292d04a commit b953270
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/core/services/rooms/room_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func (m *RoomManager) ListRoomsWithDeletionPriority(ctx context.Context, schedul
var toDeleteRooms []*game_room.GameRoom
var terminatingRooms []*game_room.GameRoom
for _, roomID := range schedulerRoomsIDs {

if len(toDeleteRooms)+len(terminatingRooms) == amount {
break
}

room, err := m.RoomStorage.GetRoom(ctx, schedulerName, roomID)
if err != nil {
if !errors.Is(err, porterrors.ErrNotFound) {
Expand All @@ -260,9 +265,6 @@ func (m *RoomManager) ListRoomsWithDeletionPriority(ctx context.Context, schedul
}

toDeleteRooms = append(toDeleteRooms, room)
if len(toDeleteRooms) == amount {
break
}
}

result := append(toDeleteRooms, terminatingRooms...)
Expand Down
8 changes: 6 additions & 2 deletions internal/core/services/rooms/room_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ func TestRoomManager_ListRoomsWithDeletionPriority(t *testing.T) {
ctx := context.Background()
schedulerName := "test-scheduler"
ignoredVersion := "v1.2.3"
expectedRooms := []*game_room.GameRoom{
{ID: "first-room", SchedulerID: schedulerName, Status: game_room.GameStatusReady, Version: "v1.1.1"},
{ID: "second-room", SchedulerID: schedulerName, Status: game_room.GameStatusTerminating, Version: "v1.1.1"},
}
availableRooms := []*game_room.GameRoom{
{ID: "first-room", SchedulerID: schedulerName, Status: game_room.GameStatusReady, Version: "v1.1.1"},
{ID: "second-room", SchedulerID: schedulerName, Status: game_room.GameStatusTerminating, Version: "v1.1.1"},
Expand All @@ -639,11 +643,11 @@ func TestRoomManager_ListRoomsWithDeletionPriority(t *testing.T) {

roomStorage.EXPECT().GetRoom(ctx, schedulerName, availableRooms[0].ID).Return(availableRooms[0], nil)
roomStorage.EXPECT().GetRoom(ctx, schedulerName, availableRooms[1].ID).Return(availableRooms[1], nil)
roomStorage.EXPECT().GetRoom(ctx, schedulerName, availableRooms[2].ID).Return(availableRooms[2], nil)

rooms, err := roomManager.ListRoomsWithDeletionPriority(ctx, schedulerName, ignoredVersion, 2, roomsBeingReplaced)
require.NoError(t, err)
require.Equal(t, availableRooms, rooms)
require.Equal(t, expectedRooms, rooms)
require.Len(t, rooms, 2)
})
}

Expand Down

0 comments on commit b953270

Please sign in to comment.