Skip to content

Commit

Permalink
feat(scheduler_test): test task returned internal context error
Browse files Browse the repository at this point in the history
This discovers #3884.
Michal-Leszczynski authored and karol-kokoszka committed Aug 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 74d36b8 commit 648f4e3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/service/scheduler/service_integration_test.go
Original file line number Diff line number Diff line change
@@ -1047,4 +1047,44 @@ func TestServiceScheduleIntegration(t *testing.T) {
Print("Then: task stops with the status done")
h.assertStatus(task, scheduler.StatusDone)
})

t.Run("task ends with context error", func(t *testing.T) {
h := newSchedTestHelper(t, session)
defer h.close()
ctx := context.Background()

Print("When: task is scheduled")
task := h.makeTask(scheduler.Schedule{
StartDate: now(),
})
if err := h.service.PutTask(ctx, task); err != nil {
t.Fatal(err)
}

Print("Then: task runs")
h.assertStatus(task, scheduler.StatusRunning)

Print("When: task ends with context.Canceled")
h.runner.in <- context.Canceled

Print("Then: task ends with status error")
h.assertStatus(task, scheduler.StatusError)

Print("When: another task is scheduled")
task = h.makeTask(scheduler.Schedule{
StartDate: now(),
})
if err := h.service.PutTask(ctx, task); err != nil {
t.Fatal(err)
}

Print("Then: task runs")
h.assertStatus(task, scheduler.StatusRunning)

Print("When: task ends with context.DeadlineExceeded")
h.runner.in <- context.DeadlineExceeded

Print("Then: task ends with status error")
h.assertStatus(task, scheduler.StatusError)
})
}

0 comments on commit 648f4e3

Please sign in to comment.