summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-04-20 01:40:22 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-04-20 01:40:40 +0300
commit46feee2d3aa59b8cd6f2f90e99c5a06f63cc3c60 (patch)
tree6bee7c3de9450090d6a464f8e0b66cd3f1ab084f /tests
parentb1a011c9436e0d47e4646f21e6c54335aa47ab05 (diff)
downloadapscheduler-46feee2d3aa59b8cd6f2f90e99c5a06f63cc3c60.tar.gz
Fixed SQLAlchemy stores failing on multiple schedule release
This only happened where RETURNING was supported for updates (PostgreSQL). Fixes #621.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_datastores.py52
1 files changed, 18 insertions, 34 deletions
diff --git a/tests/test_datastores.py b/tests/test_datastores.py
index 2b8faea..d6376ea 100644
--- a/tests/test_datastores.py
+++ b/tests/test_datastores.py
@@ -99,7 +99,7 @@ async def asyncpg_store() -> AsyncDataStore:
@pytest.fixture(
params=[
pytest.param(lazy_fixture("memory_store"), id="memory"),
- pytest.param(lazy_fixture("sqlite"), id="sqlite"),
+ pytest.param(lazy_fixture("sqlite_store"), id="sqlite"),
pytest.param(
lazy_fixture("mongodb_store"),
id="mongodb",
@@ -111,42 +111,9 @@ async def asyncpg_store() -> AsyncDataStore:
marks=[pytest.mark.external_service],
),
pytest.param(
- lazy_fixture("mysql_store"),
- id="mysql",
- marks=[pytest.mark.external_service],
- ),
- ]
-)
-def sync_store(request) -> DataStore:
- return request.param
-
-
-@pytest.fixture(
- params=[
- pytest.param(
lazy_fixture("asyncpg_store"),
id="asyncpg",
marks=[pytest.mark.external_service],
- )
- ]
-)
-def async_store(request) -> AsyncDataStore:
- return request.param
-
-
-@pytest.fixture(
- params=[
- pytest.param(lazy_fixture("memory_store"), id="memory"),
- pytest.param(lazy_fixture("sqlite_store"), id="sqlite"),
- pytest.param(
- lazy_fixture("mongodb_store"),
- id="mongodb",
- marks=[pytest.mark.external_service],
- ),
- pytest.param(
- lazy_fixture("psycopg2_store"),
- id="psycopg2",
- marks=[pytest.mark.external_service],
),
pytest.param(
lazy_fixture("mysql_store"),
@@ -371,6 +338,23 @@ class TestAsyncStores:
assert len(remaining) == 1
assert remaining[0].id == schedules[1].id
+ async def test_release_two_schedules_at_once(
+ self, datastore: AsyncDataStore
+ ) -> None:
+ """Regression test for #621."""
+ async with datastore:
+ for i in range(2):
+ trigger = DateTrigger(datetime(2020, 9, 13, tzinfo=timezone.utc))
+ schedule = Schedule(id=f"s{i}", task_id="task1", trigger=trigger)
+ schedule.next_fire_time = trigger.next()
+ await datastore.add_schedule(schedule, ConflictPolicy.exception)
+
+ schedules = await datastore.acquire_schedules("foo", 3)
+ await datastore.release_schedules("foo", schedules)
+
+ remaining = await datastore.get_schedules({s.id for s in schedules})
+ assert len(remaining) == 2
+
async def test_acquire_schedules_lock_timeout(
self, datastore: AsyncDataStore, schedules: list[Schedule], freezer
) -> None: