Skip to content

Commit 0708d65

Browse files
committed
test(sandbox): address PTY cleanup review feedback
1 parent 68036ee commit 0708d65

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎tests/extensions/sandbox/test_blaxel.py‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,22 +2001,23 @@ async def close(self) -> None:
20012001
session._reserved_pty_process_ids.update({1, 2})
20022002

20032003
task = asyncio.create_task(session.pty_terminate_all())
2004-
await close_started.wait()
2005-
2006-
# Ownership has already left the registry before cleanup finishes.
2007-
assert session._pty_sessions == {}
2008-
assert session._reserved_pty_process_ids == set()
2009-
2010-
task.cancel()
2011-
await asyncio.sleep(0)
2012-
task.cancel() # Exercise repeated caller cancellation.
2013-
await asyncio.sleep(0)
2014-
assert not first_ws._closed
2015-
assert not second_ws._closed
2016-
2017-
release_close.set()
2018-
with pytest.raises(asyncio.CancelledError):
2019-
await task
2004+
try:
2005+
await asyncio.wait_for(close_started.wait(), timeout=5)
2006+
2007+
# Ownership has already left the registry before cleanup finishes.
2008+
assert session._pty_sessions == {}
2009+
assert session._reserved_pty_process_ids == set()
2010+
2011+
task.cancel()
2012+
await asyncio.sleep(0)
2013+
task.cancel() # Exercise repeated caller cancellation.
2014+
await asyncio.sleep(0)
2015+
assert not first_ws._closed
2016+
assert not second_ws._closed
2017+
finally:
2018+
release_close.set()
2019+
with pytest.raises(asyncio.CancelledError):
2020+
await task
20202021

20212022
assert first_ws._closed and first_http._closed
20222023
assert second_ws._closed and second_http._closed

‎tests/sandbox/test_base_sandbox_session.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import sys
45

56
import pytest
67

@@ -52,7 +53,8 @@ async def cleanup() -> None:
5253
with pytest.raises(asyncio.CancelledError) as exc_info:
5354
await task
5455
assert completed
55-
assert exc_info.value.args == ("cleanup requested",)
56+
if sys.version_info >= (3, 11):
57+
assert exc_info.value.args == ("cleanup requested",)
5658

5759

5860
@pytest.mark.asyncio
@@ -71,7 +73,8 @@ async def cleanup() -> None:
7173

7274
with pytest.raises(asyncio.CancelledError) as exc_info:
7375
await task
74-
assert exc_info.value.args == ("caller stopped cleanup",)
76+
if sys.version_info >= (3, 11):
77+
assert exc_info.value.args == ("caller stopped cleanup",)
7578

7679

7780
@pytest.mark.asyncio

0 commit comments

Comments
 (0)