Job record sometimes not visible in tests #1142
-
Hi there, I have some logic in my app that makes use of I've written a test which inherits from The jobs are enqeued in an after_commit hook, could that be part of the problem? It wouldn't surprise me if this doesn't have anything to do with GoodJob or I'm just doing something stupid but I thought I'd check here first. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Oof, there's a lot of variables here. (Aside: I'm really glad you're writing tests around usage of I recently helped debug an issue where the problem was transactional fixtures/tests and threads. But, what you described could be an Can you tell me what execution mode GoodJob is using in your test? (Something like Also, can you share more of the test code? I'm curious if you're able to isolate it down to what specifically is failing e.g. are no jobs ever running, or ever finishing, or is just one job that sometimes errors slightly more/less than expected. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply, I really appreciate how in-depth you are going when trying to debug user issues with your gem. Through trial and error I suspect that concurrency control plays a role here. For some reason sometimes jobs just don't get enqueued. After I removed the limit the test started to pass consistently on CI. I've somewhat confirmed this by inspecting the return value of I have 3 distinct job classes being enqueued, which all basically just use the model id as the concurrency key, nothing more. I suspect the concurrency key is not scoped to the job class. Job A with key "XYZ" enqueues, while job B after with the same key does not. That would also explain the CI failures. I don't have many tests and the chance of overlapping ids is, depending on the execution order, not that unlikely. Here's some debug stuff to confirm:
Since I am passing in model instances I should probably lock against the GID instead of just the plain ID. Can you confirm? |
Beta Was this translation helpful? Give feedback.
happy to help 😊 That definitely sounds plausible that the concurrency key is colliding and unable to differentiate between model primary keys. I'd try doing
model.to_global_id.to_s
as the concurrency key instead.