Skip to content

Commit 7187904

Browse files
author
Hugo Osvaldo Barrera
committed
Tidy up test collection creation
- No need to empty collections, they're generated with a UUID and should always be empty (the code to empty them does not actually run in CI right now). - Move deletion code to _after_ the yield, since that's the order in which things happen. - Delete all collections asynchronously.
1 parent 17f422c commit 7187904

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

tests/storage/conftest.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import asyncio
12
import contextlib
23
import subprocess
34
import time
45
import uuid
6+
from typing import Type
57

68
import aiostream
79
import pytest
@@ -87,26 +89,26 @@ async def slow_create_collection(request, aio_connector):
8789
# storage limits.
8890
to_delete = []
8991

90-
async def delete_collections():
91-
for s in to_delete:
92-
await s.session.request("DELETE", "")
92+
async def inner(cls: Type, args: dict, collection_name: str) -> dict:
93+
"""Create a collection
9394
94-
async def inner(cls, args, collection):
95-
assert collection.startswith("test")
96-
collection += "-vdirsyncer-ci-" + str(uuid.uuid4())
95+
Returns args necessary to create a Storage instance pointing to it.
96+
"""
97+
assert collection_name.startswith("test")
9798

98-
args = await cls.create_collection(collection, **args)
99-
s = cls(**args)
100-
await _clear_collection(s)
101-
assert not await aiostream.stream.list(s.list())
102-
to_delete.append(s)
103-
return args
99+
# Make each name unique
100+
collection_name = f"{collection_name}-vdirsyncer-ci-{uuid.uuid4()}"
104101

105-
yield inner
102+
# Create the collection:
103+
args = await cls.create_collection(collection_name, **args)
104+
collection = cls(**args)
106105

107-
await delete_collections()
106+
# Keep collection in a list to be deleted once tests end:
107+
to_delete.append(collection)
108108

109+
assert not await aiostream.stream.list(collection.list())
110+
return args
111+
112+
yield inner
109113

110-
async def _clear_collection(s):
111-
async for href, etag in s.list():
112-
s.delete(href, etag)
114+
await asyncio.gather(*(c.session.request("DELETE", "") for c in to_delete))

0 commit comments

Comments
 (0)