Skip to content

Commit

Permalink
feat(job): add test panic occurred
Browse files Browse the repository at this point in the history
  • Loading branch information
trungdlp-wolffun committed Jun 19, 2024
1 parent c9dfa9e commit a1db5a1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,27 @@ func TestJob_NextRuns(t *testing.T) {
})
}
}

func TestJob_PanicOccurred(t *testing.T) {
var got any
s := newTestScheduler(t)
_, err := s.NewJob(
DurationJob(10*time.Millisecond),
NewTask(func() {
a := 0
_ = 1 / a
}),
WithEventListeners(
AfterJobRunsWithPanic(func(_ uuid.UUID, _ string, recoverData any) {
got = recoverData
}),
),
)
require.NoError(t, err)

s.Start()
time.Sleep(15 * time.Millisecond)
require.EqualError(t, got.(error), "runtime error: integer divide by zero")

require.NoError(t, s.Shutdown())
}

0 comments on commit a1db5a1

Please sign in to comment.