|
| 1 | +import asyncio |
1 | 2 | import contextlib
|
2 | 3 | import subprocess
|
3 | 4 | import time
|
4 | 5 | import uuid
|
| 6 | +from typing import Type |
5 | 7 |
|
6 | 8 | import aiostream
|
7 | 9 | import pytest
|
@@ -87,26 +89,26 @@ async def slow_create_collection(request, aio_connector):
|
87 | 89 | # storage limits.
|
88 | 90 | to_delete = []
|
89 | 91 |
|
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 |
93 | 94 |
|
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") |
97 | 98 |
|
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()}" |
104 | 101 |
|
105 |
| - yield inner |
| 102 | + # Create the collection: |
| 103 | + args = await cls.create_collection(collection_name, **args) |
| 104 | + collection = cls(**args) |
106 | 105 |
|
107 |
| - await delete_collections() |
| 106 | + # Keep collection in a list to be deleted once tests end: |
| 107 | + to_delete.append(collection) |
108 | 108 |
|
| 109 | + assert not await aiostream.stream.list(collection.list()) |
| 110 | + return args |
| 111 | + |
| 112 | + yield inner |
109 | 113 |
|
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