Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix count of rooms with deletion priority #559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 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,12 @@ func (m *RoomManager) ListRoomsWithDeletionPriority(ctx context.Context, schedul
var toDeleteRooms []*game_room.GameRoom
var terminatingRooms []*game_room.GameRoom
for _, roomID := range schedulerRoomsIDs {

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

room, err := m.RoomStorage.GetRoom(ctx, schedulerName, roomID)
if err != nil {
if !errors.Is(err, porterrors.ErrNotFound) {
Expand All @@ -260,9 +266,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