From a9f1a5195af3dab55e62a45e2c4387e18d7fe872 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sat, 12 Jun 2021 17:56:25 +0200 Subject: [PATCH 1/3] Tweak output when running tests --- setup.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e09d9db..1608e93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,8 +6,9 @@ addopts = --tb=short --cov-config .coveragerc --cov=vdirsyncer - --cov-report=term-missing + --cov-report=term-missing:skip-covered --no-cov-on-fail + --color=yes # filterwarnings=error [flake8] From 17f422c1b7e7ad45f8d1d5ca38782de65dc144b3 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sat, 12 Jun 2021 18:42:39 +0200 Subject: [PATCH 2/3] Auto-delete test containers --- tests/storage/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/storage/conftest.py b/tests/storage/conftest.py index f0c9a12..06eb69b 100644 --- a/tests/storage/conftest.py +++ b/tests/storage/conftest.py @@ -46,6 +46,7 @@ def dockerised_server(name, container_port, exposed_port): [ "docker", "run", + "--rm", "--detach", "--publish", f"{exposed_port}:{container_port}", From 71879045e4ccb75ff9637176f5bf037398f1e07d Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sun, 27 Jun 2021 13:14:17 +0200 Subject: [PATCH 3/3] 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. --- tests/storage/conftest.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/storage/conftest.py b/tests/storage/conftest.py index 06eb69b..e0cbf76 100644 --- a/tests/storage/conftest.py +++ b/tests/storage/conftest.py @@ -1,7 +1,9 @@ +import asyncio import contextlib import subprocess import time import uuid +from typing import Type import aiostream import pytest @@ -87,26 +89,26 @@ async def slow_create_collection(request, aio_connector): # storage limits. to_delete = [] - async def delete_collections(): - for s in to_delete: - await s.session.request("DELETE", "") + async def inner(cls: Type, args: dict, collection_name: str) -> dict: + """Create a collection - async def inner(cls, args, collection): - assert collection.startswith("test") - collection += "-vdirsyncer-ci-" + str(uuid.uuid4()) + Returns args necessary to create a Storage instance pointing to it. + """ + assert collection_name.startswith("test") - args = await cls.create_collection(collection, **args) - s = cls(**args) - await _clear_collection(s) - assert not await aiostream.stream.list(s.list()) - to_delete.append(s) + # Make each name unique + collection_name = f"{collection_name}-vdirsyncer-ci-{uuid.uuid4()}" + + # Create the collection: + 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 yield inner - await delete_collections() - - -async def _clear_collection(s): - async for href, etag in s.list(): - s.delete(href, etag) + await asyncio.gather(*(c.session.request("DELETE", "") for c in to_delete))