From a4b7851d5d7e46754ba01f02ebf96e58063f0fd7 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Wed, 25 Nov 2026 06:49:29 +0100 Subject: [PATCH] test: retry the teardown's deletes on CalDAV tidy_up() deleted what a test stored in a borrowed collection in one try, so a DELETE that robur dropped failed the test's teardown. Those deletes now go through sweep() as well, which the CalDAV test module already overrides to retry. As in caldav's own test cleanup, a delete that finds nothing is taken as done and is not checked afterwards: a later run sweeps whatever stays. Deleting a collection the test made is not retried here; caldav's Calendar.delete() already retries where the server's hints call calendar deletion fragile. Prompts: > just do the retries [= the retries for the teardown's deletes on > robur, left out of the sweep change] > (on a review finding that teardown now passes when a delete finds > nothing) I don't think we should spend a lot of effort verifying > that the calendar disappeared during cleanup - unless the caldav > server hint says that deleting is fragile. Consider that the > teardown shouldn't take too much time, and that it may anyway be > needed to do cleanup on the start of the test (because the test may > have been interrupted without performing any teardown earlier). > Also, check that the cleanup mechanisms in the calendaring-client is > more or less in sync with the cleanup meachnisms (sic) in the caldav > library. Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- news/+crashed-run-swept.breaking.rst | 2 +- src/calendaring/_async/conformance.py | 11 ++++++++--- src/calendaring/_sync/conformance.py | 11 ++++++++--- tests/_async/test_caldav_conformance.py | 2 +- tests/_async/test_memory_conformance.py | 5 +++++ tests/_sync/test_caldav_conformance.py | 2 +- tests/_sync/test_memory_conformance.py | 5 +++++ 7 files changed, 29 insertions(+), 9 deletions(-) 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)