Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/js-sdk/tests/sandbox/pty/kill.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { sandboxTest } from '../../setup'
import { assert, expect } from 'vitest'
import { ProcessExitError } from '../../../src/index.js'

sandboxTest('kill PTY', async ({ sandbox }) => {
const terminal = await sandbox.pty.create({
cols: 80,
rows: 24,
onData: () => {},
})

const result = await sandbox.pty.kill(terminal.pid)
assert.isTrue(result)

// The PTY process should no longer be running.
await expect(
sandbox.commands.run(`kill -0 ${terminal.pid}`)
).rejects.toThrowError(ProcessExitError)
})

sandboxTest('kill non-existing PTY', async ({ sandbox }) => {
const nonExistingPid = 999999

await expect(sandbox.pty.kill(nonExistingPid)).resolves.toBe(false)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from e2b import AsyncSandbox, CommandExitException
from e2b.sandbox.commands.command_handle import PtySize


async def test_kill_pty(async_sandbox: AsyncSandbox):
terminal = await async_sandbox.pty.create(PtySize(80, 24), on_data=lambda _: None)

assert await async_sandbox.pty.kill(terminal.pid)

# The PTY process should no longer be running.
with pytest.raises(CommandExitException):
await async_sandbox.commands.run(f"kill -0 {terminal.pid}")


async def test_kill_non_existing_pty(async_sandbox: AsyncSandbox):
non_existing_pid = 999999

assert not await async_sandbox.pty.kill(non_existing_pid)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from e2b import Sandbox, CommandExitException
from e2b.sandbox.commands.command_handle import PtySize


def test_kill_pty(sandbox: Sandbox):
terminal = sandbox.pty.create(PtySize(80, 24))

assert sandbox.pty.kill(terminal.pid)

# The PTY process should no longer be running.
with pytest.raises(CommandExitException):
sandbox.commands.run(f"kill -0 {terminal.pid}")


def test_kill_non_existing_pty(sandbox: Sandbox):
non_existing_pid = 999999

assert not sandbox.pty.kill(non_existing_pid)
Loading