Skip to content

Commit f986c47

Browse files
author
Andrei Neagu
committed
refactor test
1 parent fa82a7d commit f986c47

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

services/dynamic-sidecar/tests/unit/api/rpc/test__containers_long_running_tasks.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
from models_library.projects_nodes_io import NodeID
3131
from models_library.services_creation import CreateServiceMetricsAdditionalParams
3232
from pytest_mock.plugin import MockerFixture
33+
from pytest_simcore.helpers.long_running_tasks import (
34+
assert_task_is_no_longer_present,
35+
get_fastapi_long_running_manager,
36+
)
3337
from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict
3438
from servicelib.fastapi.long_running_tasks._manager import FastAPILongRunningManager
3539
from servicelib.long_running_tasks import lrt_api
36-
from servicelib.long_running_tasks.errors import TaskNotFoundError
3740
from servicelib.long_running_tasks.models import LRTNamespace, TaskId
38-
from servicelib.long_running_tasks.task import TaskRegistry, TasksManager
41+
from servicelib.long_running_tasks.task import TaskRegistry
3942
from servicelib.rabbitmq import RabbitMQRPCClient
4043
from servicelib.rabbitmq.rpc_interfaces.dynamic_sidecar import (
4144
containers,
@@ -54,7 +57,6 @@
5457
)
5558
from tenacity import (
5659
AsyncRetrying,
57-
TryAgain,
5860
retry_if_exception_type,
5961
stop_after_delay,
6062
wait_fixed,
@@ -190,12 +192,6 @@ def lrt_namespace(app: FastAPI) -> LRTNamespace:
190192
return long_running_manager.lrt_namespace
191193

192194

193-
@pytest.fixture
194-
def tasks_manager(app: FastAPI) -> TasksManager:
195-
tasks_manager: TasksManager = app.state.long_running_manager.tasks_manager
196-
return tasks_manager
197-
198-
199195
@pytest.fixture
200196
def shared_store(app: FastAPI) -> SharedStore:
201197
return app.state.shared_store
@@ -525,9 +521,9 @@ async def test_create_containers_task_invalid_yaml_spec(
525521
async def test_same_task_id_is_returned_if_task_exists(
526522
mock_sidecar_lrts: None,
527523
rpc_client: RabbitMQRPCClient,
524+
app: FastAPI,
528525
node_id: NodeID,
529526
lrt_namespace: LRTNamespace,
530-
tasks_manager: TasksManager,
531527
mocker: MockerFixture,
532528
get_task_id_callable: Callable[..., Awaitable[TaskId]],
533529
mock_stop_heart_beat_task: AsyncMock,
@@ -546,16 +542,9 @@ def _get_awaitable() -> Awaitable[TaskId]:
546542

547543
async def _assert_task_removed(task_id: TaskId) -> None:
548544
await lrt_api.remove_task(rpc_client, lrt_namespace, {}, task_id)
549-
async for attempt in AsyncRetrying(
550-
wait=wait_fixed(0.1),
551-
stop=stop_after_delay(5),
552-
retry=retry_if_exception_type((AssertionError, TryAgain)),
553-
reraise=True,
554-
):
555-
with attempt: # noqa: SIM117
556-
with pytest.raises(TaskNotFoundError): # noqa: PT012
557-
await tasks_manager._get_tracked_task(task_id, {}) # noqa: SLF001
558-
raise TryAgain
545+
await assert_task_is_no_longer_present(
546+
get_fastapi_long_running_manager(app), task_id, {}
547+
)
559548

560549
task_id = await _get_awaitable()
561550
assert task_id.endswith("unique")

0 commit comments

Comments
 (0)