summaryrefslogtreecommitdiff
path: root/tests/test_datastores.py
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-07-24 14:08:25 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-07-24 14:37:52 +0300
commit5c757bff12bc5ca4fecc3ea492285978caad4ec0 (patch)
tree6fb5ed5ad351b7dc32b85fd157c4c61f5b866520 /tests/test_datastores.py
parentf215c1ab45959095f6b499eb7b26356c5937ee8b (diff)
downloadapscheduler-5c757bff12bc5ca4fecc3ea492285978caad4ec0.tar.gz
Fixed CancelScope errors when the startup or shutdown of AsyncDataStoreAdapter is cancelled
Diffstat (limited to 'tests/test_datastores.py')
-rw-r--r--tests/test_datastores.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/tests/test_datastores.py b/tests/test_datastores.py
index ea5416e..0b594cf 100644
--- a/tests/test_datastores.py
+++ b/tests/test_datastores.py
@@ -10,6 +10,7 @@ from typing import Any, AsyncGenerator, cast
import anyio
import pytest
from _pytest.fixtures import SubRequest
+from anyio import CancelScope
from freezegun.api import FrozenDateTimeFactory
from pytest_lazyfixture import lazy_fixture
@@ -614,13 +615,17 @@ class TestAsyncDataStores:
),
]
)
- async def datastore(
+ async def raw_datastore(
self, request: SubRequest, event_broker: AsyncEventBroker
+ ) -> AsyncDataStore:
+ return cast(AsyncDataStore, request.param)
+
+ async def datastore(
+ self, raw_datastore: AsyncDataStore, event_broker: AsyncEventBroker
) -> AsyncGenerator[AsyncDataStore, Any]:
- datastore = cast(AsyncDataStore, request.param)
- await datastore.start(event_broker)
- yield datastore
- await datastore.stop()
+ await raw_datastore.start(event_broker)
+ yield raw_datastore
+ await raw_datastore.stop()
async def test_add_replace_task(self, datastore: AsyncDataStore) -> None:
import math
@@ -1012,3 +1017,19 @@ class TestAsyncDataStores:
)
acquired_jobs = await datastore.acquire_jobs("worker1", 3)
assert [job.id for job in acquired_jobs] == [jobs[2].id]
+
+ async def test_cancel_start(
+ self, raw_datastore: AsyncDataStore, event_broker: AsyncEventBroker
+ ) -> None:
+ with CancelScope() as scope:
+ scope.cancel()
+ await raw_datastore.start(event_broker)
+ await raw_datastore.stop()
+
+ async def test_cancel_stop(
+ self, raw_datastore: AsyncDataStore, event_broker: AsyncEventBroker
+ ) -> None:
+ with CancelScope() as scope:
+ await raw_datastore.start(event_broker)
+ scope.cancel()
+ await raw_datastore.stop()