riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.43k stars 90 forks source link

Fix more flaky periodic job enqueuer `*AfterStart` tests #422

Closed brandur closed 3 months ago

brandur commented 3 months ago

This one continues #416. I fixed a pair of the *AfterStart tests, but didn't look further to see that there were three more, and I guess by a stroke of luck I was running GitHub Actions at the right time and didn't encounter anymore failures (today I immediately started seeing them again when pushing).

Rationale there is similar to #416:

Technically, with the rewrites it can be argued that the test cases are checking slightly less, but IMO it's good enough, and I was having trouble thinking of alternative ways to add additional checks without raciness.

Fixes #386.

brandur commented 3 months ago

Just confirming, do we still have coverage on the jobs that don't run on start? We may need to look at adopting a synthetic clock for testing these reliably.

There's still plenty for non-*AfterStart tests, but yeah, these ones mostly check immediate insertion. It's not a huge stretch to think that as long as the *AfterStart functions are confirmed to get into the job bundle, they'll run.

Not against use of a synthetic clock though. It might be a little bit of work though because the synthetic clock wouldn't automatically wake the service out of its sleep loop, so you'd have to figure out how to do that.