Fix #99549: Remember Previous Status #104217

Merged
Sybren A. Stüvel merged 16 commits from Evelinealy/flamenco:web-api-upgrade into main 2023-06-02 22:50:10 +02:00
Showing only changes of commit 435817092b - Show all commits

View File

@ -290,6 +290,43 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
assertResponseNoContent(t, echo)
}
func TestWorkerRememberPreviousStatus(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mf := newMockedFlamenco(mockCtrl)
worker := testWorker()
worker.Status = api.WorkerStatusTesting
previousStatus := worker.Status
worker.StatusChangeRequest(api.WorkerStatusOffline, true)
mf.broadcaster.EXPECT().BroadcastWorkerUpdate(api.SocketIOWorkerUpdate{
Id: worker.UUID,
Name: worker.Name,
PreviousStatus: &previousStatus,
Status: api.WorkerStatusOffline,
Updated: worker.UpdatedAt,
Version: worker.Software,
})
mf.persistence.EXPECT().SaveWorkerStatus(gomock.Any(), &worker).Return(nil)
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil)
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
worker.Status = api.WorkerStatusAwake
// Preform the request
echo := mf.prepareMockedRequest(nil)
requestWorkerStore(echo, &worker)
err := mf.flamenco.SignOff(echo)
// Validate to check if status is equivalent
assert.Equal(t, previousStatus, worker.Status)
assert.NoError(t, err)
assertResponseNoContent(t, echo)
}
func TestWorkerState(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()