Commit 16d429bd authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

test: run celery monitor after the tasks finish in non EAGER mode

When running tests in non EAGER mode, tasks workflow synchronization was done
in run_all_tasks(), this seemed to work because task execution was
asynchronously finished before call to celery-monitor.

Fix this by explicitely running celery-monitor in wait_async_task which wait
the task is actually finished.
parent d0e42a42486f
......@@ -53,18 +53,14 @@ def run_all_tasks(cnx=None):
for task_eid in list(_TEST_TASKS):
results[task_eid] = _TEST_TASKS.pop(task_eid).delay()
if cnx is not None:
if celery.current_app.conf.CELERY_ALWAYS_EAGER:
for task_eid, result in results.items():
wf = cnx.entity_from_eid(task_eid).cw_adapt_to('IWorkflowable')
transition = {
STATES.SUCCESS: 'finish',
STATES.FAILURE: 'fail',
}[result.state]
wf.fire_transition(transition, result.traceback)
else:
from cubes.celerytask.ccplugin import CeleryMonitorCommand
CeleryMonitorCommand.loop(cnx, timeout=0)
if cnx is not None and celery.current_app.conf.CELERY_ALWAYS_EAGER:
for task_eid, result in results.items():
wf = cnx.entity_from_eid(task_eid).cw_adapt_to('IWorkflowable')
transition = {
STATES.SUCCESS: 'finish',
STATES.FAILURE: 'fail',
}[result.state]
wf.fire_transition(transition, result.traceback)
return results
......
......@@ -27,6 +27,7 @@ import celery.result
from celery.bin.worker import worker as celery_worker
from cubicweb.devtools import testlib
from cubes.celerytask.ccplugin import CeleryMonitorCommand
class BaseCeleryTaskTC(testlib.CubicWebTC):
......@@ -75,6 +76,7 @@ class BaseCeleryTaskTC(testlib.CubicWebTC):
start = time.time()
while abs(time.time() - start) < timeout:
if result.ready():
CeleryMonitorCommand.loop(cnx, timeout=0)
return result
if not self.worker.is_alive():
# will be joined in tearDown
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment