diff --git a/news/+crashed-run-swept.breaking.rst b/news/+crashed-run-swept.breaking.rst index b4c46d9..4acfb26 100644 --- a/news/+crashed-run-swept.breaking.rst +++ b/news/+crashed-run-swept.breaking.rst @@ -1 +1 @@ -The conformance suite now cleans up after a run that was killed before it could: every UID it writes carries a mark with the time, and a later run deletes marked items older than ``stale_after`` (a day by default) from a collection it borrows, along with what earlier versions of the suite left there. A test in a subclass that writes to a borrowed collection must give its items a UID from ``calendaring.testing.fresh_uid()``, or the test fails. Backends that assign their own UIDs are not covered. A backend whose server drops requests can override ``sweep()`` to retry those deletes. +The conformance suite now cleans up after a run that was killed before it could: every UID it writes carries a mark with the time, and a later run deletes marked items older than ``stale_after`` (a day by default) from a collection it borrows, along with what earlier versions of the suite left there. A test in a subclass that writes to a borrowed collection must give its items a UID from ``calendaring.testing.fresh_uid()``, or the test fails. Backends that assign their own UIDs are not covered. A backend whose server drops requests can override ``sweep()`` to retry those deletes, and the ones that tidy up after a test. diff --git a/src/calendaring/_async/conformance.py b/src/calendaring/_async/conformance.py index 1ea186a..1c4c0c4 100644 --- a/src/calendaring/_async/conformance.py +++ b/src/calendaring/_async/conformance.py @@ -468,8 +468,13 @@ async def seed(self, collection: AsyncCollection, items: Sequence[Item]) -> list return [await collection.add(item, loss=ALLOW) for item in items] async def sweep(self, collection: AsyncCollection, native_id: str) -> None: - """Delete an item a dead run left in a borrowed collection; one already gone is fine. A flaky backend overrides this to retry.""" - with contextlib.suppress(NotFoundError): # another run swept it first + """Delete an item of the suite's, or one a dead run left, in a borrowed collection; one already gone is fine. + + A flaky backend overrides this to retry. + """ + # Gone is the goal: another run may have swept it first. Nothing checks a delete that did + # nothing: a later run sweeps what stays, as caldav's own test cleanup trusts its deletes. + with contextlib.suppress(NotFoundError): await collection.delete(native_id) async def unseed(self, collection: AsyncCollection, item: AsyncItem) -> None: @@ -503,7 +508,7 @@ async def tidy_up(self, backend: AsyncBackend) -> None: items, _ = await readable(borrowed) for native_id in {i.native_id for i in items if self.wrote(i, before, written)}: assert native_id is not None - await borrowed.delete(native_id) + await self.sweep(borrowed, native_id) @staticmethod def left_by_a_dead_run(item: Item, cutoff: datetime) -> bool: diff --git a/src/calendaring/_sync/conformance.py b/src/calendaring/_sync/conformance.py index 91dde81..88b44b5 100644 --- a/src/calendaring/_sync/conformance.py +++ b/src/calendaring/_sync/conformance.py @@ -468,8 +468,13 @@ def seed(self, collection: Collection, items: Sequence[Item]) -> list[SyncItem]: return [collection.add(item, loss=ALLOW) for item in items] def sweep(self, collection: Collection, native_id: str) -> None: - """Delete an item a dead run left in a borrowed collection; one already gone is fine. A flaky backend overrides this to retry.""" - with contextlib.suppress(NotFoundError): # another run swept it first + """Delete an item of the suite's, or one a dead run left, in a borrowed collection; one already gone is fine. + + A flaky backend overrides this to retry. + """ + # Gone is the goal: another run may have swept it first. Nothing checks a delete that did + # nothing: a later run sweeps what stays, as caldav's own test cleanup trusts its deletes. + with contextlib.suppress(NotFoundError): collection.delete(native_id) def unseed(self, collection: Collection, item: SyncItem) -> None: @@ -503,7 +508,7 @@ def tidy_up(self, backend: Backend) -> None: items, _ = readable(borrowed) for native_id in {i.native_id for i in items if self.wrote(i, before, written)}: assert native_id is not None - borrowed.delete(native_id) + self.sweep(borrowed, native_id) @staticmethod def left_by_a_dead_run(item: Item, cutoff: datetime) -> bool: diff --git a/tests/_async/test_caldav_conformance.py b/tests/_async/test_caldav_conformance.py index 628e8be..2eb01ad 100644 --- a/tests/_async/test_caldav_conformance.py +++ b/tests/_async/test_caldav_conformance.py @@ -76,7 +76,7 @@ async def seed(self, collection: AsyncCollection, items: Sequence[Item]) -> list return seeded async def sweep(self, collection: AsyncCollection, native_id: str) -> None: - """Delete a dead run's leftover, again after a failed DELETE: robur drops requests as it does while seeding. + """Delete a leftover or the test's own item, again after a failed DELETE: robur drops requests as it does while seeding. Gone on a retry is taken for a lost answer to a DELETE that went through. """ diff --git a/tests/_async/test_memory_conformance.py b/tests/_async/test_memory_conformance.py index c722b0e..81b283f 100644 --- a/tests/_async/test_memory_conformance.py +++ b/tests/_async/test_memory_conformance.py @@ -467,6 +467,11 @@ async def sweep(self, collection: AsyncCollection, native_id: str) -> None: collection = await suite.open_collection(backend) assert len(swept) == 1 assert [str(i.component["SUMMARY"]) for i in await collection.search()] == ["the user's"] + # The teardown deletes what the test stored the same way + stored = await collection.add_task(summary="the suite's", uid=fresh_uid()) + await suite.tidy_up(backend) + assert swept[1:] == [stored.native_id] + assert [str(i.component["SUMMARY"]) for i in await collection.search()] == ["the user's"] async def test_an_older_runs_unstamped_leftover_is_swept(self) -> None: backend = sharing(MINIMAL) diff --git a/tests/_sync/test_caldav_conformance.py b/tests/_sync/test_caldav_conformance.py index cf506e3..d575616 100644 --- a/tests/_sync/test_caldav_conformance.py +++ b/tests/_sync/test_caldav_conformance.py @@ -76,7 +76,7 @@ def seed(self, collection: Collection, items: Sequence[Item]) -> list[SyncItem]: return seeded def sweep(self, collection: Collection, native_id: str) -> None: - """Delete a dead run's leftover, again after a failed DELETE: robur drops requests as it does while seeding. + """Delete a leftover or the test's own item, again after a failed DELETE: robur drops requests as it does while seeding. Gone on a retry is taken for a lost answer to a DELETE that went through. """ diff --git a/tests/_sync/test_memory_conformance.py b/tests/_sync/test_memory_conformance.py index 5c703c2..7f6eddc 100644 --- a/tests/_sync/test_memory_conformance.py +++ b/tests/_sync/test_memory_conformance.py @@ -467,6 +467,11 @@ def sweep(self, collection: Collection, native_id: str) -> None: collection = suite.open_collection(backend) assert len(swept) == 1 assert [str(i.component["SUMMARY"]) for i in collection.search()] == ["the user's"] + # The teardown deletes what the test stored the same way + stored = collection.add_task(summary="the suite's", uid=fresh_uid()) + suite.tidy_up(backend) + assert swept[1:] == [stored.native_id] + assert [str(i.component["SUMMARY"]) for i in collection.search()] == ["the user's"] def test_an_older_runs_unstamped_leftover_is_swept(self) -> None: backend = sharing(MINIMAL)