From a595db8729e9af8e7406178490fb9683014f4612 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Mon, 4 Nov 2024 11:54:00 +0500 Subject: [PATCH] add test --- tests/unit/grpc_internals/zeebe_adapter_base_test.py | 11 +++++++---- tests/unit/worker/worker_test.py | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/unit/grpc_internals/zeebe_adapter_base_test.py b/tests/unit/grpc_internals/zeebe_adapter_base_test.py index ed30bda8..11bf59f2 100644 --- a/tests/unit/grpc_internals/zeebe_adapter_base_test.py +++ b/tests/unit/grpc_internals/zeebe_adapter_base_test.py @@ -69,18 +69,21 @@ async def test_raises_unkown_grpc_status_code_on_unkown_status_code( async def test_closes_after_retries_exceeded(self, zeebe_adapter: ZeebeAdapterBase): error = grpc.aio.AioRpcError(grpc.StatusCode.UNAVAILABLE, None, None) - zeebe_adapter._close = AsyncMock() + zeebe_adapter._channel.close = AsyncMock() zeebe_adapter._max_connection_retries = 1 with pytest.raises(ZeebeGatewayUnavailableError): await zeebe_adapter._handle_grpc_error(error) - zeebe_adapter._close.assert_called_once() + assert zeebe_adapter.connected is False + zeebe_adapter._channel.close.assert_awaited_once() async def test_closes_after_internal_error(self, zeebe_adapter: ZeebeAdapterBase): error = grpc.aio.AioRpcError(grpc.StatusCode.INTERNAL, None, None) - zeebe_adapter._close = AsyncMock() + + zeebe_adapter._channel.close = AsyncMock() zeebe_adapter._max_connection_retries = 1 with pytest.raises(ZeebeInternalError): await zeebe_adapter._handle_grpc_error(error) - zeebe_adapter._close.assert_called_once() + assert zeebe_adapter.connected is False + zeebe_adapter._channel.close.assert_awaited_once() diff --git a/tests/unit/worker/worker_test.py b/tests/unit/worker/worker_test.py index ef77d820..9f234604 100644 --- a/tests/unit/worker/worker_test.py +++ b/tests/unit/worker/worker_test.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio from unittest.mock import AsyncMock, Mock from uuid import uuid4 @@ -277,12 +278,12 @@ async def test_poller_failed(self, zeebe_worker: ZeebeWorker): async def test_second_poller_should_cancel(self, zeebe_worker: ZeebeWorker): zeebe_worker._init_tasks = Mock() - poller2_cancel_event = anyio.Event() + poller2_cancel_event = asyncio.Event() async def poll2(): try: - await anyio.Event().wait() - except anyio.get_cancelled_exc_class(): + await asyncio.Event().wait() + except asyncio.CancelledError: poller2_cancel_event.set() poller_mock = AsyncMock(spec_set=JobPoller, poll=AsyncMock(side_effect=[Exception("test_exception")]))