@@ -81,6 +81,7 @@ tests appPool jobPool = testGroup "All tests"
8181 , testGracefulShutdown appPool jobPool
8282 , testJobErrHandler appPool jobPool
8383 , testPushFailedJobEndQueue jobPool
84+ , testRetryBackoff appPool jobPool
8485 ]
8586 -- , testGroup "property tests" [ testEverything appPool jobPool
8687 -- -- , propFilterJobs appPool jobPool
@@ -356,6 +357,35 @@ testJobErrHandler appPool jobPool = testCase "job error handler" $ do
356357 readMVar mvar1 >>= assertEqual "Error Handler 1 doesn't seem to have run" True
357358 readMVar mvar2 >>= assertEqual "Error Handler 2 doesn't seem to have run" True
358359
360+testRetryBackoff appPool jobPool = testCase "retry backoff" $ do
361+ withRandomTable jobPool $ \tname -> do
362+ withNamedJobMonitor tname jobPool modifyRetryBackoff $ \logRef -> do
363+ Pool.withResource appPool $ \conn -> do
364+ jobQueueTime <- getCurrentTime
365+ Job{jobId} <- Job.createJob conn tname (PayloadAlwaysFail 0)
366+ delaySeconds (2 * Job.defaultPollingInterval)
367+
368+ let assertBackedOff = do
369+ job@Job{jobAttempts, jobStatus, jobRunAt} <- ensureJobId conn tname jobId
370+ assertEqual "Exepcting job to be in Retry status" Job.Retry jobStatus
371+ assertBool "Expecting job runAt to be in the future"
372+ (jobRunAt >= addUTCTime (fromIntegral $ unSeconds $ backoff jobAttempts) jobQueueTime)
373+
374+ assertBackedOff
375+
376+ -- Run it for another attempt and check the backoff scales
377+ job <- ensureJobId conn tname jobId
378+ Job.saveJobIO conn tname (job {jobRunAt = jobQueueTime})
379+ delaySeconds (2 * Job.defaultPollingInterval)
380+
381+ assertBackedOff
382+ where
383+
384+ backoff attempts = Seconds $ 300 * attempts
385+
386+ modifyRetryBackoff cfg
387+ = cfg { Job.cfgDefaultRetryBackoff = pure . backoff }
388+
359389data JobEvent = JobStart
360390 | JobRetry
361391 | JobSuccess