forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Avoid aioredis client form hanging on calls if redis is no longer a…
…vailable (ITISFoundation#5821) Co-authored-by: Andrei Neagu <[email protected]>
- Loading branch information
Showing
7 changed files
with
92 additions
and
79 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/pytest-simcore/src/pytest_simcore/container_pause.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
import contextlib | ||
from collections.abc import AsyncIterator, Callable | ||
from contextlib import AbstractAsyncContextManager | ||
|
||
import aiodocker | ||
import pytest | ||
|
||
|
||
@contextlib.asynccontextmanager | ||
async def _pause_container( | ||
async_docker_client: aiodocker.Docker, container_name: str | ||
) -> AsyncIterator[None]: | ||
containers = await async_docker_client.containers.list( | ||
filters={"name": [f"{container_name}."]} | ||
) | ||
await asyncio.gather(*(c.pause() for c in containers)) | ||
# refresh | ||
container_attrs = await asyncio.gather(*(c.show() for c in containers)) | ||
for container_status in container_attrs: | ||
assert container_status["State"]["Status"] == "paused" | ||
|
||
yield | ||
|
||
await asyncio.gather(*(c.unpause() for c in containers)) | ||
# refresh | ||
container_attrs = await asyncio.gather(*(c.show() for c in containers)) | ||
for container_status in container_attrs: | ||
assert container_status["State"]["Status"] == "running" | ||
# NOTE: container takes some time to start | ||
|
||
|
||
@pytest.fixture | ||
async def paused_container() -> Callable[[str], AbstractAsyncContextManager[None]]: | ||
@contextlib.asynccontextmanager | ||
async def _(container_name: str) -> AsyncIterator[None]: | ||
async with aiodocker.Docker() as docker_client, _pause_container( | ||
docker_client, container_name | ||
): | ||
yield None | ||
|
||
return _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters