In my django project, I have some celery tasks that must be completed after a certain time (in test mode, the wait time is set to just a few seconds). After completing these tasks, they will change some state of the objects. I wrote tests to check for these conditions right after the scheduled tasks.
I tried using CELERY_ALWAYS_EAGER = Truecelery to test tasks while testing the django module. However, with this parameter, it expects tasks to be completed locally and the results are returned. So my previous test code breaks because of this.
Let me give you a more concrete example. Say I have an ordering system for an e-commerce platform. When customers place an order, a celery task is created to check if the order is successfully completed within 24 hours. If not paid, the order must be canceled. In test mode, I can count down 20 seconds instead of 24 hours. But when testing the django module, if I use CELERY_ALWAYS_EAGER = True, then the celery task is executed immediately, so the order will always be canceled. How can I verify that the payment was successful within the deadline (20 s)?
Does anyone know how you can test celery tasks that simply cannot be completed immediately?
source
share