diff --git a/services/web/server/tests/unit/with_dbs/01/test_api_keys.py b/services/web/server/tests/unit/with_dbs/01/test_api_keys.py index b850a84ae85f..aa6d4621209b 100644 --- a/services/web/server/tests/unit/with_dbs/01/test_api_keys.py +++ b/services/web/server/tests/unit/with_dbs/01/test_api_keys.py @@ -3,7 +3,6 @@ # pylint: disable=unused-variable # pylint: disable=too-many-arguments -import asyncio from collections.abc import AsyncIterable from datetime import timedelta from http import HTTPStatus @@ -29,7 +28,12 @@ ) from simcore_service_webserver.application_settings import GarbageCollectorSettings from simcore_service_webserver.db.models import UserRole -from tenacity import retry_if_exception_type, stop_after_attempt, wait_fixed +from tenacity import ( + retry_if_exception_type, + stop_after_attempt, + stop_after_delay, + wait_fixed, +) @pytest.fixture @@ -172,9 +176,15 @@ async def test_create_api_key_with_expiration( assert [d["displayName"] for d in data] == ["foo"] # wait for api-key for it to expire and force-run scheduled task - await asyncio.sleep(expiration_interval.seconds) - deleted = await prune_expired_api_keys(client.app) - assert deleted == ["foo"] + async for attempt in tenacity.AsyncRetrying( + wait=wait_fixed(1), + retry=retry_if_exception_type(AssertionError), + stop=stop_after_delay(5 * expiration_interval.seconds), + reraise=True, + ): + with attempt: + deleted = await prune_expired_api_keys(client.app) + assert deleted == ["foo"] resp = await client.get("/v0/auth/api-keys") data, _ = await assert_status(resp, expected) diff --git a/services/web/server/tests/unit/with_dbs/02/test_projects_repository.py b/services/web/server/tests/unit/with_dbs/02/test_projects_repository.py index 4141f9527965..da2307578a65 100644 --- a/services/web/server/tests/unit/with_dbs/02/test_projects_repository.py +++ b/services/web/server/tests/unit/with_dbs/02/test_projects_repository.py @@ -3,7 +3,7 @@ # pylint: disable=unused-variable # pylint: disable=too-many-arguments -from datetime import timedelta +from datetime import datetime, timedelta from uuid import UUID import arrow @@ -55,7 +55,9 @@ async def test_patch_project( assert client.app # This will change after in patched_project - assert user_project["creationDate"] == user_project["lastChangeDate"] + creation_date = datetime.fromisoformat(user_project["creationDate"]) + last_change_date = datetime.fromisoformat(user_project["lastChangeDate"]) + assert abs(creation_date - last_change_date) < timedelta(seconds=1) # Patch valid project patch_data = {"name": "Updated Project Name"}