|
3 | 3 | # pylint: disable=unused-variable |
4 | 4 | # pylint: disable=too-many-arguments |
5 | 5 |
|
6 | | -import asyncio |
7 | 6 | from collections.abc import AsyncIterable |
8 | 7 | from datetime import timedelta |
9 | 8 | from http import HTTPStatus |
|
29 | 28 | ) |
30 | 29 | from simcore_service_webserver.application_settings import GarbageCollectorSettings |
31 | 30 | from simcore_service_webserver.db.models import UserRole |
32 | | -from tenacity import retry_if_exception_type, stop_after_attempt, wait_fixed |
| 31 | +from tenacity import ( |
| 32 | + retry_if_exception_type, |
| 33 | + stop_after_attempt, |
| 34 | + stop_after_delay, |
| 35 | + wait_fixed, |
| 36 | +) |
33 | 37 |
|
34 | 38 |
|
35 | 39 | @pytest.fixture |
@@ -172,9 +176,15 @@ async def test_create_api_key_with_expiration( |
172 | 176 | assert [d["displayName"] for d in data] == ["foo"] |
173 | 177 |
|
174 | 178 | # wait for api-key for it to expire and force-run scheduled task |
175 | | - await asyncio.sleep(expiration_interval.seconds) |
176 | | - deleted = await prune_expired_api_keys(client.app) |
177 | | - assert deleted == ["foo"] |
| 179 | + async for attempt in tenacity.AsyncRetrying( |
| 180 | + wait=wait_fixed(1), |
| 181 | + retry=retry_if_exception_type(AssertionError), |
| 182 | + stop=stop_after_delay(5 * expiration_interval.seconds), |
| 183 | + reraise=True, |
| 184 | + ): |
| 185 | + with attempt: |
| 186 | + deleted = await prune_expired_api_keys(client.app) |
| 187 | + assert deleted == ["foo"] |
178 | 188 |
|
179 | 189 | resp = await client.get("/v0/auth/api-keys") |
180 | 190 | data, _ = await assert_status(resp, expected) |
|
0 commit comments