|
| 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
|
@@ -46,6 +48,7 @@ def dockerised_server(name, container_port, exposed_port):
|
46 | 48 | [
|
47 | 49 | "docker",
|
48 | 50 | "run",
|
| 51 | + "--rm", |
49 | 52 | "--detach",
|
50 | 53 | "--publish",
|
51 | 54 | f"{exposed_port}:{container_port}",
|
@@ -86,26 +89,26 @@ async def slow_create_collection(request, aio_connector):
|
86 | 89 | # storage limits.
|
87 | 90 | to_delete = []
|
88 | 91 |
|
89 |
| - async def delete_collections(): |
90 |
| - for s in to_delete: |
91 |
| - await s.session.request("DELETE", "") |
| 92 | + async def inner(cls: Type, args: dict, collection_name: str) -> dict: |
| 93 | + """Create a collection |
92 | 94 |
|
93 |
| - async def inner(cls, args, collection): |
94 |
| - assert collection.startswith("test") |
95 |
| - 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") |
96 | 98 |
|
97 |
| - args = await cls.create_collection(collection, **args) |
98 |
| - s = cls(**args) |
99 |
| - await _clear_collection(s) |
100 |
| - assert not await aiostream.stream.list(s.list()) |
101 |
| - to_delete.append(s) |
102 |
| - return args |
| 99 | + # Make each name unique |
| 100 | + collection_name = f"{collection_name}-vdirsyncer-ci-{uuid.uuid4()}" |
103 | 101 |
|
104 |
| - yield inner |
| 102 | + # Create the collection: |
| 103 | + args = await cls.create_collection(collection_name, **args) |
| 104 | + collection = cls(**args) |
105 | 105 |
|
106 |
| - await delete_collections() |
| 106 | + # Keep collection in a list to be deleted once tests end: |
| 107 | + to_delete.append(collection) |
107 | 108 |
|
| 109 | + assert not await aiostream.stream.list(collection.list()) |
| 110 | + return args |
| 111 | + |
| 112 | + yield inner |
108 | 113 |
|
109 |
| -async def _clear_collection(s): |
110 |
| - async for href, etag in s.list(): |
111 |
| - s.delete(href, etag) |
| 114 | + await asyncio.gather(*(c.session.request("DELETE", "") for c in to_delete)) |
0 commit comments