Skip to content

Commit 4b94969

Browse files
committed
test for close/open of tab
1 parent 2febabc commit 4b94969

File tree

1 file changed

+59
-86
lines changed

1 file changed

+59
-86
lines changed

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

Lines changed: 59 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,12 +1627,11 @@ async def test_refreshing_tab_of_opened_project_multiple_users(
16271627
):
16281628
# This test is a simplified version of the test_open_shared_project_multiple_users
16291629
# It only tests refreshing the tab of an already opened project
1630-
base_client = client
16311630
(
1632-
sio_base,
1633-
base_client_tab_id,
1634-
sio_base_handlers,
1635-
) = await create_socketio_connection_with_handlers(None, base_client)
1631+
original_socketio,
1632+
client_tab_id,
1633+
original_socket_handlers,
1634+
) = await create_socketio_connection_with_handlers(None, client)
16361635

16371636
# current state is closed and unlocked
16381637
closed_project_state = ProjectStateOutputSchema(
@@ -1641,12 +1640,10 @@ async def test_refreshing_tab_of_opened_project_multiple_users(
16411640
),
16421641
state=ProjectRunningState(value=RunningState.NOT_STARTED),
16431642
)
1644-
await _state_project(
1645-
base_client, shared_project, HTTPStatus.OK, closed_project_state
1646-
)
1643+
await _state_project(client, shared_project, expected.ok, closed_project_state)
16471644

16481645
# now user opens the project
1649-
await _open_project(base_client, base_client_tab_id, shared_project, expected.ok)
1646+
await _open_project(client, client_tab_id, shared_project, expected.ok)
16501647
opened_project_state = closed_project_state.model_copy(
16511648
update={
16521649
"share_state": ProjectShareStateOutputSchema(
@@ -1657,54 +1654,50 @@ async def test_refreshing_tab_of_opened_project_multiple_users(
16571654
}
16581655
)
16591656
await _assert_project_state_updated(
1660-
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1657+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
16611658
shared_project,
16621659
[opened_project_state]
16631660
* 2, # NOTE: 2 calls since base user is part of the primary group and the all group
16641661
)
1665-
await _state_project(
1666-
base_client, shared_project, HTTPStatus.OK, opened_project_state
1667-
)
1662+
await _state_project(client, shared_project, expected.ok, opened_project_state)
16681663
# opening a second time should also work as this is a no-op
1669-
await _open_project(base_client, base_client_tab_id, shared_project, expected.ok)
1664+
await _open_project(client, client_tab_id, shared_project, expected.ok)
16701665
await _assert_project_state_updated(
1671-
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1666+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
16721667
shared_project,
16731668
[opened_project_state]
16741669
* 2, # NOTE: 2 calls since base user is part of the primary group and the all group
16751670
)
1676-
await _state_project(
1677-
base_client, shared_project, HTTPStatus.OK, opened_project_state
1678-
)
1671+
await _state_project(client, shared_project, expected.ok, opened_project_state)
16791672

16801673
# now we simulate refreshing the tab of the base user (the client session id remains the same), by disconnecting and reconnecting the socket.io
1681-
await sio_base.disconnect()
1674+
await original_socketio.disconnect()
16821675
await _assert_project_state_updated(
1683-
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1676+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
16841677
shared_project,
16851678
[],
16861679
)
16871680

16881681
# now we connect again the socket.io with a new socket
16891682
(
1690-
new_sio,
1683+
new_socketio,
16911684
new_client_tab_id,
1692-
new_sio_base_handlers,
1693-
) = await create_socketio_connection_with_handlers(base_client_tab_id, base_client)
1694-
assert new_sio
1695-
assert new_client_tab_id == base_client_tab_id, "refreshing changed the tab id!"
1685+
new_socket_handlers,
1686+
) = await create_socketio_connection_with_handlers(client_tab_id, client)
1687+
assert new_socketio
1688+
assert new_client_tab_id == client_tab_id, "refreshing changed the tab id!"
16961689

1697-
await _open_project(base_client, base_client_tab_id, shared_project, expected.ok)
1690+
await _open_project(client, client_tab_id, shared_project, expected.ok)
16981691

16991692
await _assert_project_state_updated(
1700-
new_sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1693+
new_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
17011694
shared_project,
17021695
[opened_project_state]
17031696
* 2, # NOTE: 2 calls since base user is part of the primary group and the all group
17041697
)
17051698
# check old socket is silent
17061699
await _assert_project_state_updated(
1707-
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1700+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
17081701
shared_project,
17091702
[],
17101703
)
@@ -1728,12 +1721,11 @@ async def test_closing_and_reopening_tab_of_opened_project_multiple_users(
17281721
):
17291722
# This test is a simplified version of the test_open_shared_project_multiple_users
17301723
# It only tests closing and reopening the tab of an already opened project which should still open
1731-
base_client = client
17321724
(
1733-
sio_base,
1734-
base_client_tab_id,
1735-
sio_base_handlers,
1736-
) = await create_socketio_connection_with_handlers(None, base_client)
1725+
original_socketio,
1726+
original_client_tab_id,
1727+
original_socket_handlers,
1728+
) = await create_socketio_connection_with_handlers(None, client)
17371729

17381730
# current state is closed and unlocked
17391731
closed_project_state = ProjectStateOutputSchema(
@@ -1742,12 +1734,10 @@ async def test_closing_and_reopening_tab_of_opened_project_multiple_users(
17421734
),
17431735
state=ProjectRunningState(value=RunningState.NOT_STARTED),
17441736
)
1745-
await _state_project(
1746-
base_client, shared_project, HTTPStatus.OK, closed_project_state
1747-
)
1737+
await _state_project(client, shared_project, expected.ok, closed_project_state)
17481738

17491739
# now user opens the project
1750-
await _open_project(base_client, base_client_tab_id, shared_project, expected.ok)
1740+
await _open_project(client, original_client_tab_id, shared_project, expected.ok)
17511741
opened_project_state = closed_project_state.model_copy(
17521742
update={
17531743
"share_state": ProjectShareStateOutputSchema(
@@ -1758,59 +1748,42 @@ async def test_closing_and_reopening_tab_of_opened_project_multiple_users(
17581748
}
17591749
)
17601750
await _assert_project_state_updated(
1761-
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1751+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
17621752
shared_project,
17631753
[opened_project_state]
17641754
* 2, # NOTE: 2 calls since base user is part of the primary group and the all group
17651755
)
1766-
await _state_project(
1767-
base_client, shared_project, HTTPStatus.OK, opened_project_state
1768-
)
1769-
1770-
# now we simulate refreshing the tab of the base user (the client session id remains the same)
1771-
# await sio_base.disconnect()
1772-
# await asyncio.sleep(5) # wait for the disconnect to be processed
1773-
# (
1774-
# new_sio_x,
1775-
# new_client_x_tab_id,
1776-
# new_sio_x_handlers,
1777-
# ) = await create_socketio_connection_with_handlers(client_x)
1778-
# await _assert_project_state_updated(
1779-
# new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1780-
# shared_project,
1781-
# [],
1782-
# )
1783-
1784-
# await _open_project(client_x, new_client_x_tab_id, shared_project, expected.ok)
1785-
1786-
# await _assert_project_state_updated(
1787-
# new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1788-
# shared_project,
1789-
# [opened_project_state],
1790-
# )
1791-
1792-
# # put back the refreshed user in the list of other users
1793-
# other_users.append(
1794-
# (user_x, client_x, new_client_x_tab_id, new_sio_x, new_sio_x_handlers)
1795-
# )
1796-
# # this triggers the new opening of the same users
1797-
# for _user_j, client_j, _, _sio_j, sio_j_handlers in other_users:
1798-
# # check already opened by other users which should also notify
1799-
# await _assert_project_state_updated(
1800-
# sio_j_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1801-
# shared_project,
1802-
# [opened_project_state],
1803-
# )
1804-
# await _state_project(
1805-
# client_j, shared_project, expected.ok, opened_project_state
1806-
# )
1807-
1808-
# await _assert_project_state_updated(
1809-
# sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1810-
# shared_project,
1811-
# [opened_project_state]
1812-
# * 2, # NOTE: 2 calls since base user is part of the primary group and the all group
1813-
# )
1756+
await _state_project(client, shared_project, expected.ok, opened_project_state)
1757+
1758+
# now we simulate refreshing the tab of the base user (the client session id DOES NOT remain the same)
1759+
await original_socketio.disconnect()
1760+
await asyncio.sleep(5) # wait for the disconnect to be processed
1761+
(
1762+
new_socketio,
1763+
new_client_session_id,
1764+
new_socketio_handlers,
1765+
) = await create_socketio_connection_with_handlers(None, client)
1766+
assert original_client_tab_id != new_client_session_id
1767+
await _assert_project_state_updated(
1768+
new_socketio_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1769+
shared_project,
1770+
[],
1771+
)
1772+
# re-open the project with the new socket / tab id
1773+
await _open_project(client, new_client_session_id, shared_project, expected.ok)
1774+
1775+
await _assert_project_state_updated(
1776+
new_socketio_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1777+
shared_project,
1778+
[opened_project_state]
1779+
* 2, # NOTE: 2 calls since base user is part of the primary group and the all group
1780+
)
1781+
# check old socket is silent
1782+
await _assert_project_state_updated(
1783+
original_socket_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1784+
shared_project,
1785+
[],
1786+
)
18141787

18151788

18161789
@pytest.mark.parametrize(*standard_user_role_response())

0 commit comments

Comments
 (0)