Skip to content

Commit

Permalink
fix: setting running matches when not given
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldooli committed Jan 15, 2025
1 parent 5f7ed06 commit 3850d7f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions e2e/framework/maestro/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ services:
- MAESTRO_ADAPTERS_INSTANCESTORAGE_REDIS_URL=redis://redis:6379/0
- MAESTRO_ADAPTERS_RUNTIME_KUBERNETES_KUBECONFIG=/kubeconfig/kubeconfig.yaml
- MAESTRO_ADAPTERS_RUNTIME_KUBERNETES_MASTERURL=https://k3s_server:6443
- MAESTRO_ADAPTERS_RUNTIME_KUBERNETES_TOPOLOGYSPREADCONSTRAINT_ENABLED=false
- MAESTRO_ADAPTERS_SCHEDULERCACHE_REDIS_URL=redis://redis:6379/0
- MAESTRO_INTERNALAPI_PORT=8051
- MAESTRO_WORKERS_HEALTHCONTROLLERINTERVAL=5s
Expand Down
4 changes: 2 additions & 2 deletions e2e/suites/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ func requireEventualState(t *testing.T, numberOfReadyRooms, numberOfOccupiedRoom
return schedulerInfo.GetRoomsReady() == int32(numberOfReadyRooms) &&
schedulerInfo.GetRoomsOccupied() == int32(numberOfOccupiedRooms)
},
time.Minute*3,
time.Second*1,
time.Minute*4,
time.Millisecond*500,
fmt.Sprintf("Timeout waiting for scheduler %s to reach expected state: ready %d, occupied %d", schedulerName, numberOfReadyRooms, numberOfOccupiedRooms),
)

Expand Down
2 changes: 1 addition & 1 deletion e2e/suites/cancel_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestCancelOperation(t *testing.T) {
finishedOpCancelResponse := &maestroApiV1.CancelOperationResponse{}
err = managementApiClient.Do("POST", fmt.Sprintf("/schedulers/%s/operations/%s/cancel", scheduler.Name, finishedOpId), finishedOpCancelRequest, finishedOpCancelResponse)
require.Error(t, err)
require.Contains(t, err.Error(), "status 409")
require.Contains(t, err.Error(), "status: 409")
})
})
}
9 changes: 5 additions & 4 deletions e2e/suites/create_new_scheduler_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCreateNewSchedulerVersion(t *testing.T) {
// ----------- Create new Major version v2.0.0 and assert pods are replaced
newVersionExpected = "v2.0.0"
createMajorVersionAndAssertPodsReplace(t, roomsBeforeUpdate, kubeClient, scheduler, maestro, managementApiClient, roomsApiClient, newVersionExpected)
// ----------- Switch back to v1.0.0
// --------ru--- Switch back to v1.0.0
podsAfterSwitch := switchVersion(t, scheduler, managementApiClient, kubeClient, "v1.0.0")
// ----------- Create new Minor version v1.2.0 (since v1.1.0 already exists) and assert pods are not replaced
newVersionExpected = "v1.2.0"
Expand Down Expand Up @@ -222,6 +222,7 @@ func switchVersion(t *testing.T, scheduler *maestrov1.Scheduler, managementApiCl

waitForOperationToFinishByOperationId(t, managementApiClient, scheduler.Name, switchActiveVersionResponse.OperationId)

// waiting termination of pods
require.Eventually(t, func() bool {
podsAfterUpdate, err := kubeClient.CoreV1().Pods(scheduler.Name).List(context.Background(), metav1.ListOptions{})
require.NoError(t, err)
Expand All @@ -232,7 +233,7 @@ func switchVersion(t *testing.T, scheduler *maestrov1.Scheduler, managementApiCl
}

return false
}, 1*time.Minute, time.Second*10, "Timeout waiting to have 2 pods after switch version")
}, 2*time.Minute, time.Second*10, "Timeout waiting to have 2 pods after switch version")

podsAfterUpdate, err := kubeClient.CoreV1().Pods(scheduler.Name).List(context.Background(), metav1.ListOptions{})
require.NoError(t, err)
Expand Down Expand Up @@ -553,8 +554,8 @@ func createMinorVersionAndAssertNoPodsReplace(t *testing.T, kubeClient kubernete
}
require.ElementsMatch(t, podsNameAfterUpdate, podsNameBeforeUpdate)

require.Contains(t, getSchedulerResponse.Scheduler.Annotations, updateRequest.Annotations)
require.Contains(t, getSchedulerResponse.Scheduler.Labels, updateRequest.Labels)
require.Equal(t, getSchedulerResponse.Scheduler.Annotations, updateRequest.Annotations)
require.Equal(t, getSchedulerResponse.Scheduler.Labels, updateRequest.Labels)

require.Equal(t, expectedNewVersion, getSchedulerResponse.Scheduler.Spec.Version)
}
2 changes: 1 addition & 1 deletion e2e/suites/delete_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestDeleteScheduler(t *testing.T) {
err := managementApiClient.Do("DELETE", fmt.Sprintf("/schedulers/%s", schedulerName), deleteSchedulerRequest, deleteSchedulerResponse)

assert.Error(t, err)
assert.Contains(t, err.Error(), "failed with status 404")
assert.Contains(t, err.Error(), "failed with status: 404")
})
})
}
2 changes: 1 addition & 1 deletion e2e/suites/patch_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestPatchScheduler(t *testing.T) {
patchSchedulerResponse := &maestrov1.PatchSchedulerResponse{}
err = managementApiClient.Do("PATCH", fmt.Sprintf("/schedulers/%s", scheduler.Name), patchSchedulerRequest, patchSchedulerResponse)
require.Error(t, err)
require.Contains(t, err.Error(), "failed with status 409")
require.Contains(t, err.Error(), "failed with status: 409")
getSchedulerRequest = &maestrov1.GetSchedulerRequest{}
getSchedulerResponse = &maestrov1.GetSchedulerResponse{}
err = managementApiClient.Do("GET", fmt.Sprintf("/schedulers/%s", scheduler.Name), getSchedulerRequest, getSchedulerResponse)
Expand Down
2 changes: 2 additions & 0 deletions e2e/suites/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func createSchedulerWithForwardersAndWaitForIt(
RoomsReplicas: 2,
MaxSurge: "10%",
Forwarders: forwarders,
Annotations: map[string]string{"annotation-key": "annotation-value"},
Labels: map[string]string{"label-key": "label-value"},
}

createResponse := &maestroApiV1.CreateSchedulerResponse{}
Expand Down
7 changes: 6 additions & 1 deletion internal/api/handlers/requestadapters/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ func FromApiUpdateRoomRequestToEntity(request *api.UpdateRoomWithPingRequest) (*
return nil, err
}

runningMatches := request.GetRunningMatches()
if status == game_room.GameRoomPingStatusOccupied && runningMatches == 0 {
runningMatches = 1
}

return &game_room.GameRoom{
ID: request.GetRoomName(),
SchedulerID: request.GetSchedulerName(),
PingStatus: status,
Metadata: request.Metadata.AsMap(),
LastPingAt: time.Unix(request.GetTimestamp(), 0),
RunningMatches: int(request.GetRunningMatches()),
RunningMatches: int(runningMatches),
}, nil
}

Expand Down

0 comments on commit 3850d7f

Please sign in to comment.