-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathtest_async_interrupt.py
More file actions
25 lines (19 loc) · 930 Bytes
/
test_async_interrupt.py
File metadata and controls
25 lines (19 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import asyncio
import pytest
from e2b import TimeoutException
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
async def test_subsequent_execution_works_after_client_timeout(
async_sandbox: AsyncSandbox,
):
# Start a long-running execution with a short timeout.
# This simulates a client disconnect: the SDK closes the connection,
# which should trigger the server to interrupt the kernel (#213).
with pytest.raises(TimeoutException):
await async_sandbox.run_code("import time; time.sleep(300)", timeout=3)
# Wait for the server to detect the disconnect (via keepalive write
# failure) and interrupt the kernel.
await asyncio.sleep(5)
# Run a simple execution. Without the kernel interrupt fix, this would
# block behind the still-running sleep(30) and time out.
result = await async_sandbox.run_code("1 + 1", timeout=10)
assert result.text == "2"