abodnar's avatar

How to unit test the requeue/failure of a job?

I'm working on a job that if it fails I want to make sure it's requeued/released. So while writing up unit tests for it, I wanted to test that the failure logic works appropriately which is to be released back to the queue. I've not seeing anything in 5.2 to do this, but it looks like maybe this is possible 5.3 with https://laravel.com/docs/5.3/mocking#using-job-fakes

Is there a way to assert/validate this occurred?

0 likes
3 replies
ifpingram's avatar

@abodnar I presume you are on 5.2 and not 5.3? Are you trying to achieve assertPushed() and assertNotPushed()? If so, why not take a look at those methods in 5.3 and see if they give you any ideas?

abodnar's avatar

Yes, I'm on 5.2 and can't do the migration to 5.3 yet due to timelines. I'll definitely take a look at those functions, but at least from my initial glance, it looks like it's relying on a bit of code that's only available in 5.3.

mjlovefl's avatar

assertPushed() and assertNotPushed() are not testing that a job failed. They only tests if a job was queued or not.

1 like

Please or to participate in this conversation.