mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix connection check (#5787)
This commit is contained in:
@@ -421,8 +421,8 @@ class SessionManager:
|
||||
# Clear up local variables
|
||||
connection_ids_to_remove = list(
|
||||
connection_id
|
||||
for connection_id, sid in self.local_connection_id_to_session_id.items()
|
||||
if sid == sid
|
||||
for connection_id, conn_sid in self.local_connection_id_to_session_id.items()
|
||||
if sid == conn_sid
|
||||
)
|
||||
logger.info(f'removing connections: {connection_ids_to_remove}')
|
||||
for connnnection_id in connection_ids_to_remove:
|
||||
|
||||
@@ -237,3 +237,36 @@ async def test_add_to_cluster_event_stream():
|
||||
'oh_event',
|
||||
'{"sid": "new-session-id", "message_type": "event", "data": {"event_type": "some_event"}}',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cleanup_session_connections():
|
||||
sio = get_mock_sio()
|
||||
with (
|
||||
patch('openhands.server.session.manager._REDIS_POLL_TIMEOUT', 0.01),
|
||||
patch(
|
||||
'openhands.server.session.manager.SessionManager._redis_subscribe',
|
||||
AsyncMock(),
|
||||
),
|
||||
):
|
||||
async with SessionManager(
|
||||
sio, AppConfig(), InMemoryFileStore()
|
||||
) as session_manager:
|
||||
session_manager.local_connection_id_to_session_id.update(
|
||||
{
|
||||
'conn1': 'session1',
|
||||
'conn2': 'session1',
|
||||
'conn3': 'session2',
|
||||
'conn4': 'session2',
|
||||
}
|
||||
)
|
||||
|
||||
await session_manager._close_session('session1')
|
||||
|
||||
remaining_connections = session_manager.local_connection_id_to_session_id
|
||||
assert 'conn1' not in remaining_connections
|
||||
assert 'conn2' not in remaining_connections
|
||||
assert 'conn3' in remaining_connections
|
||||
assert 'conn4' in remaining_connections
|
||||
assert remaining_connections['conn3'] == 'session2'
|
||||
assert remaining_connections['conn4'] == 'session2'
|
||||
|
||||
Reference in New Issue
Block a user