Skip to content

Commit 4ef3f22

Browse files
author
Andrei Neagu
committed
fixed tests
1 parent 5c7f6c8 commit 4ef3f22

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pylint: disable=no-member
2+
# pylint: disable=protected-access
23
# pylint: disable=redefined-outer-name
34
# pylint: disable=too-many-arguments
45
# pylint: disable=unused-argument
@@ -34,7 +35,7 @@
3435
from servicelib.long_running_tasks import lrt_api
3536
from servicelib.long_running_tasks.errors import TaskNotFoundError
3637
from servicelib.long_running_tasks.models import LRTNamespace, TaskId
37-
from servicelib.long_running_tasks.task import TaskRegistry
38+
from servicelib.long_running_tasks.task import TaskRegistry, TasksManager
3839
from servicelib.rabbitmq import RabbitMQRPCClient
3940
from servicelib.rabbitmq.rpc_interfaces.dynamic_sidecar import (
4041
containers,
@@ -53,6 +54,7 @@
5354
)
5455
from tenacity import (
5556
AsyncRetrying,
57+
TryAgain,
5658
retry_if_exception_type,
5759
stop_after_delay,
5860
wait_fixed,
@@ -188,6 +190,12 @@ def lrt_namespace(app: FastAPI) -> LRTNamespace:
188190
return long_running_manager.lrt_namespace
189191

190192

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+
191199
@pytest.fixture
192200
def shared_store(app: FastAPI) -> SharedStore:
193201
return app.state.shared_store
@@ -519,6 +527,7 @@ async def test_same_task_id_is_returned_if_task_exists(
519527
rpc_client: RabbitMQRPCClient,
520528
node_id: NodeID,
521529
lrt_namespace: LRTNamespace,
530+
tasks_manager: TasksManager,
522531
mocker: MockerFixture,
523532
get_task_id_callable: Callable[..., Awaitable[TaskId]],
524533
mock_stop_heart_beat_task: AsyncMock,
@@ -537,8 +546,16 @@ def _get_awaitable() -> Awaitable[TaskId]:
537546

538547
async def _assert_task_removed(task_id: TaskId) -> None:
539548
await lrt_api.remove_task(rpc_client, lrt_namespace, {}, task_id)
540-
with pytest.raises(TaskNotFoundError):
541-
await lrt_api.get_task_status(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
542559

543560
task_id = await _get_awaitable()
544561
assert task_id.endswith("unique")

0 commit comments

Comments
 (0)