Skip to content

Commit

Permalink
add suppress cancelation test
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyann committed Aug 4, 2024
1 parent 9c4e19d commit b047f6b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/unit/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,37 @@ async def task_func():
assert task_cancelled


async def test_stopping_worker_job_suppresses_cancellation(app: App, worker):
complete_task_event = asyncio.Event()
worker.shutdown_timeout = 0.02

@app.task()
async def task_func():
try:
await complete_task_event.wait()
except asyncio.CancelledError:
# supress the cancellation
pass

run_task = await start_worker(worker)

job_id = await task_func.defer_async()

await asyncio.sleep(0.05)

# this should still be running waiting for the task to complete
assert run_task.done() is False

worker.stop()

await asyncio.sleep(0.1)
assert run_task.done()
await run_task

status = await app.job_manager.get_job_status_async(job_id)
assert status == Status.SUCCEEDED


@pytest.mark.parametrize(
"worker",
[({"additional_context": {"foo": "bar"}})],
Expand Down

0 comments on commit b047f6b

Please sign in to comment.