Skip to content

Commit 4fb0d0d

Browse files
committed
cleanup
1 parent de86066 commit 4fb0d0d

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

packages/pytest-simcore/src/pytest_simcore/socketio_client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,15 @@ async def _create(client_override: TestClient | None = None) -> str:
4545
assert data
4646
assert not error
4747

48-
return (
49-
resp.request_info.headers["Cookie"]
50-
if "Cookie" in resp.request_info.headers
51-
else ""
52-
)
48+
return resp.request_info.headers.get("Cookie", "")
5349

5450
return _create
5551

5652

5753
@pytest.fixture
5854
async def socketio_client_factory(
59-
socketio_url_factory: Callable,
60-
security_cookie_factory: Callable,
55+
socketio_url_factory: Callable[[TestClient | None], str],
56+
security_cookie_factory: Callable[[TestClient | None], Awaitable[str]],
6157
client_session_id_factory: Callable[[], str],
6258
) -> AsyncIterable[
6359
Callable[[str | None, TestClient | None], Awaitable[socketio.AsyncClient]]

services/web/server/tests/unit/with_dbs/02/test_projects_states_handlers.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ class _SocketHandlers(TypedDict):
169169

170170

171171
@pytest.fixture
172-
async def create_socketio_connection(
173-
socketio_client_factory: Callable,
172+
async def create_socketio_connection_with_handlers(
173+
socketio_client_factory: Callable[
174+
[str | None, TestClient | None], Awaitable[socketio.AsyncClient]
175+
],
174176
mocker: MockerFixture,
175-
) -> AsyncIterator[
176-
Callable[[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]]
177+
) -> Callable[
178+
[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]
177179
]:
178180
connected_sockets = []
179181

@@ -192,12 +194,7 @@ async def _(
192194
connected_sockets.append(sio)
193195
return sio, event_handlers
194196

195-
yield _
196-
197-
# cleanup
198-
with log_context(logging.INFO, "disconnecting sockets"):
199-
await asyncio.gather(*(socket.disconnect() for socket in connected_sockets))
200-
await asyncio.sleep(0.1) # give time to properly disconnect
197+
return _
201198

202199

203200
async def _open_project(
@@ -1393,15 +1390,15 @@ async def test_open_shared_project_multiple_users(
13931390
client_session_id_factory: Callable[[], str],
13941391
expected: ExpectedResponse,
13951392
exit_stack: contextlib.AsyncExitStack,
1396-
create_socketio_connection: Callable[
1393+
create_socketio_connection_with_handlers: Callable[
13971394
[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]
13981395
],
13991396
mocked_dynamic_services_interface: dict[str, mock.Mock],
14001397
mock_catalog_api: dict[str, mock.Mock],
14011398
):
14021399
base_client = client
14031400
base_client_tab_id = client_session_id_factory()
1404-
sio_base, sio_base_handlers = await create_socketio_connection(
1401+
sio_base, sio_base_handlers = await create_socketio_connection_with_handlers(
14051402
base_client,
14061403
base_client_tab_id,
14071404
)
@@ -1443,7 +1440,7 @@ async def test_open_shared_project_multiple_users(
14431440
LoggedUser(client_i, {"role": logged_user["role"]})
14441441
)
14451442

1446-
sio_i, sio_i_handlers = await create_socketio_connection(
1443+
sio_i, sio_i_handlers = await create_socketio_connection_with_handlers(
14471444
client_i, client_i_tab_id
14481445
)
14491446

@@ -1497,7 +1494,7 @@ async def test_open_shared_project_2_users_locked_remove_once_rtc_collaboration_
14971494
mock_dynamic_scheduler_rabbitmq: None,
14981495
mocked_notifications_plugin: dict[str, mock.Mock],
14991496
exit_stack: contextlib.AsyncExitStack,
1500-
create_socketio_connection: Callable[
1497+
create_socketio_connection_with_handlers: Callable[
15011498
[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]
15021499
],
15031500
):
@@ -1509,7 +1506,9 @@ async def test_open_shared_project_2_users_locked_remove_once_rtc_collaboration_
15091506
client_id2 = client_session_id_factory()
15101507

15111508
# 1. user 1 opens project
1512-
sio1, sio1_handlers = await create_socketio_connection(client_1, client_id1)
1509+
sio1, sio1_handlers = await create_socketio_connection_with_handlers(
1510+
client_1, client_id1
1511+
)
15131512
# expected is that the project is closed and unlocked
15141513
expected_project_state_client_1 = ProjectStateOutputSchema(
15151514
share_state=ProjectShareStateOutputSchema(
@@ -1564,7 +1563,9 @@ async def test_open_shared_project_2_users_locked_remove_once_rtc_collaboration_
15641563
enable_check=user_role != UserRole.ANONYMOUS,
15651564
exit_stack=exit_stack,
15661565
)
1567-
sio2, sio2_handlers = await create_socketio_connection(client_2, client_id2)
1566+
sio2, sio2_handlers = await create_socketio_connection_with_handlers(
1567+
client_2, client_id2
1568+
)
15681569
await _open_project(
15691570
client_2,
15701571
client_id2,
@@ -1733,15 +1734,15 @@ async def test_open_shared_project_at_same_time(
17331734
mock_dynamic_scheduler_rabbitmq: None,
17341735
mocked_notifications_plugin: dict[str, mock.Mock],
17351736
exit_stack: contextlib.AsyncExitStack,
1736-
create_socketio_connection: Callable[
1737+
create_socketio_connection_with_handlers: Callable[
17371738
[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]
17381739
],
17391740
):
17401741
NUMBER_OF_ADDITIONAL_CLIENTS = 10
17411742
# log client 1
17421743
client_1 = client
17431744
client_id1 = client_session_id_factory()
1744-
sio_1 = await create_socketio_connection(client_1, client_id1)
1745+
sio_1 = await create_socketio_connection_with_handlers(client_1, client_id1)
17451746
clients = [
17461747
{"client": client_1, "user": logged_user, "client_id": client_id1, "sio": sio_1}
17471748
]
@@ -1755,7 +1756,7 @@ async def test_open_shared_project_at_same_time(
17551756
exit_stack=exit_stack,
17561757
)
17571758
client_id = client_session_id_factory()
1758-
sio = await create_socketio_connection(new_client, client_id)
1759+
sio = await create_socketio_connection_with_handlers(new_client, client_id)
17591760
clients.append(
17601761
{"client": new_client, "user": user, "client_id": client_id, "sio": sio}
17611762
)
@@ -1816,7 +1817,7 @@ async def test_opened_project_can_still_be_opened_after_refreshing_tab(
18161817
mock_catalog_api: dict[str, mock.Mock],
18171818
clean_redis_table,
18181819
mocked_notifications_plugin: dict[str, mock.Mock],
1819-
create_socketio_connection: Callable[
1820+
create_socketio_connection_with_handlers: Callable[
18201821
[TestClient, str], Awaitable[tuple[socketio.AsyncClient, _SocketHandlers]]
18211822
],
18221823
):
@@ -1827,7 +1828,7 @@ async def test_opened_project_can_still_be_opened_after_refreshing_tab(
18271828
"""
18281829

18291830
client_session_id = client_session_id_factory()
1830-
sio, _ = await create_socketio_connection(client, client_session_id)
1831+
sio, _ = await create_socketio_connection_with_handlers(client, client_session_id)
18311832
assert client.app
18321833
url = client.app.router["open_project"].url_for(project_id=user_project["uuid"])
18331834
resp = await client.post(f"{url}", json=client_session_id)
@@ -1843,7 +1844,7 @@ async def test_opened_project_can_still_be_opened_after_refreshing_tab(
18431844
# give some time
18441845
await asyncio.sleep(1)
18451846
# re-connect using the same client session id
1846-
sio2, _ = await create_socketio_connection(client, client_session_id)
1847+
sio2, _ = await create_socketio_connection_with_handlers(client, client_session_id)
18471848
assert sio2
18481849
# re-open the project
18491850
resp = await client.post(f"{url}", json=client_session_id)

0 commit comments

Comments
 (0)