mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Merge pull request #911 from pimutils/optimise-test-servers
Minor optimisations to tests
This commit is contained in:
commit
21db2547cb
2 changed files with 22 additions and 18 deletions
|
|
@ -6,8 +6,9 @@ addopts =
|
||||||
--tb=short
|
--tb=short
|
||||||
--cov-config .coveragerc
|
--cov-config .coveragerc
|
||||||
--cov=vdirsyncer
|
--cov=vdirsyncer
|
||||||
--cov-report=term-missing
|
--cov-report=term-missing:skip-covered
|
||||||
--no-cov-on-fail
|
--no-cov-on-fail
|
||||||
|
--color=yes
|
||||||
# filterwarnings=error
|
# filterwarnings=error
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
import aiostream
|
import aiostream
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -46,6 +48,7 @@ def dockerised_server(name, container_port, exposed_port):
|
||||||
[
|
[
|
||||||
"docker",
|
"docker",
|
||||||
"run",
|
"run",
|
||||||
|
"--rm",
|
||||||
"--detach",
|
"--detach",
|
||||||
"--publish",
|
"--publish",
|
||||||
f"{exposed_port}:{container_port}",
|
f"{exposed_port}:{container_port}",
|
||||||
|
|
@ -86,26 +89,26 @@ async def slow_create_collection(request, aio_connector):
|
||||||
# storage limits.
|
# storage limits.
|
||||||
to_delete = []
|
to_delete = []
|
||||||
|
|
||||||
async def delete_collections():
|
async def inner(cls: Type, args: dict, collection_name: str) -> dict:
|
||||||
for s in to_delete:
|
"""Create a collection
|
||||||
await s.session.request("DELETE", "")
|
|
||||||
|
|
||||||
async def inner(cls, args, collection):
|
Returns args necessary to create a Storage instance pointing to it.
|
||||||
assert collection.startswith("test")
|
"""
|
||||||
collection += "-vdirsyncer-ci-" + str(uuid.uuid4())
|
assert collection_name.startswith("test")
|
||||||
|
|
||||||
args = await cls.create_collection(collection, **args)
|
# Make each name unique
|
||||||
s = cls(**args)
|
collection_name = f"{collection_name}-vdirsyncer-ci-{uuid.uuid4()}"
|
||||||
await _clear_collection(s)
|
|
||||||
assert not await aiostream.stream.list(s.list())
|
# Create the collection:
|
||||||
to_delete.append(s)
|
args = await cls.create_collection(collection_name, **args)
|
||||||
|
collection = cls(**args)
|
||||||
|
|
||||||
|
# Keep collection in a list to be deleted once tests end:
|
||||||
|
to_delete.append(collection)
|
||||||
|
|
||||||
|
assert not await aiostream.stream.list(collection.list())
|
||||||
return args
|
return args
|
||||||
|
|
||||||
yield inner
|
yield inner
|
||||||
|
|
||||||
await delete_collections()
|
await asyncio.gather(*(c.session.request("DELETE", "") for c in to_delete))
|
||||||
|
|
||||||
|
|
||||||
async def _clear_collection(s):
|
|
||||||
async for href, etag in s.list():
|
|
||||||
s.delete(href, etag)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue