diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2017-12-13 00:41:58 +0200 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2017-12-13 00:41:58 +0200 |
commit | 7cad405ac074d13e2615c2e7aa65af5d243dfd1f (patch) | |
tree | 0d8bb03118dcf7862b34ae5326770cca4788a767 /tests | |
parent | 488cd5cfd74bcfa71b7b493e14f30af90ee2156e (diff) | |
download | apscheduler-7cad405ac074d13e2615c2e7aa65af5d243dfd1f.tar.gz |
Cancel all pending futures on AsyncIOExecutor shutdown
Fixes #233.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_executors_py35.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_executors_py35.py b/tests/test_executors_py35.py index cc25d88..7849eb0 100644 --- a/tests/test_executors_py35.py +++ b/tests/test_executors_py35.py @@ -1,4 +1,5 @@ """Contains test functions using Python 3.3+ syntax.""" +from asyncio import CancelledError from datetime import datetime import pytest @@ -84,3 +85,18 @@ async def test_run_coroutine_job_tornado(tornado_scheduler, tornado_executor, ex assert str(events[0].exception) == 'dummy error' else: assert events[0].retval is True + + +@pytest.mark.asyncio +async def test_asyncio_executor_shutdown(asyncio_scheduler, asyncio_executor): + """Test that the AsyncIO executor cancels its pending tasks on shutdown.""" + from asyncio import sleep + + job = asyncio_scheduler.add_job(waiter, 'interval', seconds=1, args=[sleep, None]) + asyncio_executor.submit_job(job, [datetime.now(utc)]) + futures = asyncio_executor._pending_futures.copy() + assert len(futures) == 1 + + asyncio_executor.shutdown() + with pytest.raises(CancelledError): + await futures.pop() |