Manager: add test for saving task status change with error on job save
This commit is contained in:
parent
d2f1cf3614
commit
e8707171b4
@ -22,6 +22,7 @@ package task_state_machine
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -52,6 +53,25 @@ func TestTaskStatusChangeQueuedToActive(t *testing.T) {
|
|||||||
assert.NoError(t, sm.TaskStatusChange(ctx, task, api.TaskStatusActive))
|
assert.NoError(t, sm.TaskStatusChange(ctx, task, api.TaskStatusActive))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTaskStatusChangeSaveTaskAfterJobChangeFailure(t *testing.T) {
|
||||||
|
mockCtrl, ctx, sm, mocks := taskStateMachineTestFixtures(t)
|
||||||
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
|
// A task status change should be saved, even when triggering the job change errors somehow.
|
||||||
|
task := taskWithStatus(api.JobStatusQueued, api.TaskStatusQueued)
|
||||||
|
|
||||||
|
jobSaveErr := errors.New("hypothetical job save error")
|
||||||
|
mocks.persist.EXPECT().
|
||||||
|
SaveJobStatus(gomock.Any(), task.Job).
|
||||||
|
Return(jobSaveErr)
|
||||||
|
|
||||||
|
// Expect a call to save the task in the persistence layer, regardless of the above error.
|
||||||
|
mocks.expectSaveTaskWithStatus(t, task, api.TaskStatusActive)
|
||||||
|
|
||||||
|
returnedErr := sm.TaskStatusChange(ctx, task, api.TaskStatusActive)
|
||||||
|
assert.ErrorIs(t, returnedErr, jobSaveErr, "the returned error should wrap the persistence layer error")
|
||||||
|
}
|
||||||
|
|
||||||
func TestTaskStatusChangeActiveToCompleted(t *testing.T) {
|
func TestTaskStatusChangeActiveToCompleted(t *testing.T) {
|
||||||
mockCtrl, ctx, sm, mocks := taskStateMachineTestFixtures(t)
|
mockCtrl, ctx, sm, mocks := taskStateMachineTestFixtures(t)
|
||||||
defer mockCtrl.Finish()
|
defer mockCtrl.Finish()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user