Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion news/+crashed-run-swept.breaking.rst
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 8 additions & 3 deletions src/calendaring/_async/conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions src/calendaring/_sync/conformance.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/_async/test_caldav_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/_async/test_memory_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/test_caldav_conformance.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/_sync/test_memory_conformance.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading