|
7 | 7 |
|
8 | 8 | import asyncio |
9 | 9 | import contextlib |
| 10 | +import logging |
10 | 11 | from collections.abc import AsyncIterator, Awaitable, Callable, Iterator |
11 | 12 | from copy import deepcopy |
12 | 13 | from datetime import UTC, datetime, timedelta |
|
49 | 50 | from models_library.utils.fastapi_encoders import jsonable_encoder |
50 | 51 | from pytest_mock import MockerFixture |
51 | 52 | from pytest_simcore.helpers.assert_checks import assert_status |
| 53 | +from pytest_simcore.helpers.logging_tools import log_context |
52 | 54 | from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict |
53 | 55 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
54 | 56 | from pytest_simcore.helpers.webserver_login import log_client_in |
|
70 | 72 | from simcore_service_webserver.utils import to_datetime |
71 | 73 | from socketio.exceptions import ConnectionError as SocketConnectionError |
72 | 74 | from tenacity import ( |
| 75 | + RetryError, |
| 76 | + before_sleep_log, |
73 | 77 | retry, |
74 | 78 | retry_if_exception_type, |
75 | | - retry_never, |
| 79 | + retry_unless_exception_type, |
76 | 80 | stop_after_delay, |
77 | 81 | wait_fixed, |
78 | 82 | ) |
@@ -243,39 +247,44 @@ async def _assert_project_state_updated( |
243 | 247 | shared_project: dict, |
244 | 248 | expected_project_state_updates: list[ProjectStateOutputSchema], |
245 | 249 | ) -> None: |
246 | | - @retry( |
247 | | - wait=wait_fixed(1), |
248 | | - stop=stop_after_delay(15), |
249 | | - retry=retry_if_exception_type(AssertionError), |
250 | | - reraise=True, |
251 | | - ) |
252 | | - async def _received_project_update_event() -> None: |
253 | | - assert handler.call_count == len( |
254 | | - expected_project_state_updates |
255 | | - ), f"got only {handler.call_count}/{len(expected_project_state_updates)} expected calls" |
256 | | - if expected_project_state_updates: |
257 | | - calls = [ |
258 | | - call( |
259 | | - jsonable_encoder( |
260 | | - { |
261 | | - "project_uuid": shared_project["uuid"], |
262 | | - "data": p_state.model_dump( |
263 | | - by_alias=True, exclude_unset=True |
264 | | - ), |
265 | | - } |
| 250 | + with log_context(logging.INFO, "assert_project_state_updated") as ctx: |
| 251 | + |
| 252 | + @retry( |
| 253 | + wait=wait_fixed(1), |
| 254 | + stop=stop_after_delay(15), |
| 255 | + retry=retry_if_exception_type(AssertionError), |
| 256 | + reraise=True, |
| 257 | + before_sleep=before_sleep_log(ctx.logger, logging.INFO), |
| 258 | + ) |
| 259 | + async def _received_project_update_event() -> None: |
| 260 | + assert handler.call_count == len( |
| 261 | + expected_project_state_updates |
| 262 | + ), f"got only {handler.call_count}/{len(expected_project_state_updates)} expected calls" |
| 263 | + if expected_project_state_updates: |
| 264 | + calls = [ |
| 265 | + call( |
| 266 | + jsonable_encoder( |
| 267 | + { |
| 268 | + "project_uuid": shared_project["uuid"], |
| 269 | + "data": p_state.model_dump( |
| 270 | + by_alias=True, exclude_unset=True |
| 271 | + ), |
| 272 | + } |
| 273 | + ) |
266 | 274 | ) |
267 | | - ) |
268 | | - for p_state in expected_project_state_updates |
269 | | - ] |
270 | | - handler.assert_has_calls(calls) |
271 | | - handler.reset_mock() |
272 | | - |
273 | | - if not expected_project_state_updates: |
274 | | - await _received_project_update_event.retry_with( |
275 | | - stop=stop_after_delay(3), retry=retry_never |
276 | | - )() |
277 | | - else: |
278 | | - await _received_project_update_event() |
| 275 | + for p_state in expected_project_state_updates |
| 276 | + ] |
| 277 | + handler.assert_has_calls(calls) |
| 278 | + handler.reset_mock() |
| 279 | + |
| 280 | + if not expected_project_state_updates: |
| 281 | + with contextlib.suppress(RetryError): |
| 282 | + await _received_project_update_event.retry_with( |
| 283 | + stop=stop_after_delay(3), |
| 284 | + retry=retry_unless_exception_type(AssertionError), |
| 285 | + )() |
| 286 | + else: |
| 287 | + await _received_project_update_event() |
279 | 288 |
|
280 | 289 |
|
281 | 290 | async def _delete_project(client: TestClient, project: dict) -> ClientResponse: |
@@ -1382,6 +1391,9 @@ async def test_open_shared_project_multiple_users( |
1382 | 1391 | base_client, |
1383 | 1392 | base_client_tab_id, |
1384 | 1393 | ) |
| 1394 | + await _assert_project_state_updated( |
| 1395 | + socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT], shared_project, [] |
| 1396 | + ) |
1385 | 1397 |
|
1386 | 1398 |
|
1387 | 1399 | @pytest.mark.parametrize(*standard_user_role_response()) |
|
0 commit comments