Skip to content

Commit 21db254

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #911 from pimutils/optimise-test-servers
Minor optimisations to tests
2 parents be131a0 + 7187904 commit 21db254

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ addopts =
66
--tb=short
77
--cov-config .coveragerc
88
--cov=vdirsyncer
9-
--cov-report=term-missing
9+
--cov-report=term-missing:skip-covered
1010
--no-cov-on-fail
11+
--color=yes
1112
# filterwarnings=error
1213

1314
[flake8]

tests/storage/conftest.py

Lines changed: 20 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
@@ -46,6 +48,7 @@ def dockerised_server(name, container_port, exposed_port):
4648
[
4749
"docker",
4850
"run",
51+
"--rm",
4952
"--detach",
5053
"--publish",
5154
f"{exposed_port}:{container_port}",
@@ -86,26 +89,26 @@ async def slow_create_collection(request, aio_connector):
8689
# storage limits.
8790
to_delete = []
8891

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
9294
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")
9698

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()}"
103101

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

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

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

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

Comments
 (0)