|
5 | 5 |
|
6 | 6 | import asyncio |
7 | 7 | from collections.abc import Awaitable, Callable |
8 | | -from typing import Any |
9 | 8 | from unittest.mock import AsyncMock |
10 | 9 |
|
11 | 10 | import pytest |
|
18 | 17 | @pytest.fixture |
19 | 18 | def long_running_poller_mock( |
20 | 19 | monkeypatch: pytest.MonkeyPatch, |
21 | | -) -> Callable[[asyncio.Event, Request, Any], Awaitable]: |
| 20 | +) -> Callable[[asyncio.Event, Request], Awaitable]: |
22 | 21 |
|
23 | | - async def _mock_disconnect_poller( |
24 | | - close_event: asyncio.Event, request: Request, result: Any |
25 | | - ): |
| 22 | + async def _mock_disconnect_poller(close_event: asyncio.Event, request: Request): |
26 | 23 | _mock_disconnect_poller.called = True |
27 | 24 | while not await request.is_disconnected(): |
28 | | - await asyncio.sleep(0.01) |
| 25 | + await asyncio.sleep(2) |
29 | 26 | if close_event.is_set(): |
30 | | - # Simulate a long cleanup procedure |
31 | | - await asyncio.sleep(POLLER_CLEANUP_DELAY_S) |
32 | 27 | break |
33 | | - return result |
34 | 28 |
|
35 | 29 | monkeypatch.setattr( |
36 | | - "servicelib.fastapi.requests_decorators._disconnect_poller", |
| 30 | + "servicelib.fastapi.requests_decorators._disconnect_poller_for_task_group", |
37 | 31 | _mock_disconnect_poller, |
38 | 32 | ) |
39 | 33 | return _mock_disconnect_poller |
40 | 34 |
|
41 | 35 |
|
42 | 36 | async def test_decorator_waits_for_poller_cleanup( |
43 | | - long_running_poller_mock: Callable[[asyncio.Event, Request, Any], Awaitable], |
| 37 | + long_running_poller_mock: Callable[[asyncio.Event, Request], Awaitable], |
44 | 38 | ): |
45 | 39 | """ |
46 | 40 | Tests that the decorator's wrapper waits for the poller task to finish |
|
0 commit comments