-
Notifications
You must be signed in to change notification settings - Fork 886
Expand file tree
/
Copy pathtest_cmd_kill.py
More file actions
38 lines (25 loc) · 1.29 KB
/
test_cmd_kill.py
File metadata and controls
38 lines (25 loc) · 1.29 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
import pytest
from e2b import AsyncSandbox, CommandExitException
async def test_kill_process(async_sandbox: AsyncSandbox):
cmd = await async_sandbox.commands.run("sleep 10", background=True)
pid = cmd.pid
await async_sandbox.commands.kill(pid)
with pytest.raises(CommandExitException):
await async_sandbox.commands.run(f"kill -0 {pid}")
async def test_kill_non_existing_process(async_sandbox: AsyncSandbox):
non_existing_pid = 999999
assert not await async_sandbox.commands.kill(non_existing_pid)
async def test_kill_via_handle(async_sandbox: AsyncSandbox):
handle = await async_sandbox.commands.run("sleep 60", background=True)
killed = await handle.kill()
assert killed is True
with pytest.raises(CommandExitException):
await async_sandbox.commands.run(f"kill -0 {handle.pid}")
async def test_kill_handle_wait_raises(async_sandbox: AsyncSandbox):
handle = await async_sandbox.commands.run("sleep 60", background=True)
await handle.kill()
# Before the fix: this blocks forever (or until the 5s timeout fires as TimeoutError).
# After the fix: raises CommandExitException promptly because the process was killed.
with pytest.raises(CommandExitException):
await asyncio.wait_for(handle.wait(), timeout=5.0)