Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for terminating the terminals #142

Merged
merged 21 commits into from
Mar 3, 2022
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
7 changes: 5 additions & 2 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Check Release
on:
push:
branches: ["master"]
branches: ["main"]
pull_request:
branches: ["*"]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
check_release:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Tests

on:
push:
branches: "*"
branches: ["main"]
pull_request:
branches: "*"
schedule:
- cron: "0 8 * * *"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}-latest
Expand Down
3 changes: 3 additions & 0 deletions terminado/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def preexec_fn():
except ImportError:
try:
from winpty import PtyProcess as PtyProcessUnicode
from winpty.enums import Backend
except ImportError:
PtyProcessUnicode = object
preexec_fn = None
Expand All @@ -45,6 +46,8 @@ def __init__(self, argv, env=[], cwd=None):
kwargs = dict(argv=argv, env=env, cwd=cwd)
if preexec_fn is not None:
kwargs["preexec_fn"] = preexec_fn
if os.name == 'nt':
kwargs.setdefault('backend', Backend.WinPTY)
self.ptyproc = PtyProcessUnicode.spawn(**kwargs)
# The output might not be strictly UTF-8 encoded, so
# we replace the inner decoder of PtyProcessUnicode
Expand Down
20 changes: 11 additions & 9 deletions terminado/tests/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,9 @@ async def get_pid(self):
await self.write_stdin("echo $$\r")
(stdout, extra) = await self.read_stdout()
if os.name == 'nt':
print(repr(stdout))
match = re.search(r'echo \$\$\\x1b\[71X\\x1b\[71C\\r\\n(\d+)', repr(stdout))
if match is None:
match = re.search(r'echo \$\$ \\r\\n(\d+)', repr(stdout))
if match is None:
match = re.search(
r'echo \$\$ \\r\\n\\x1b\[\?25h\\x1b\[\?25l(\d+)',
repr(stdout))
match = re.search(r'echo \$\$\\.*?\\r\\n(\d+)', repr(stdout))
pid = int(match.groups()[0])
else:
print('stdout=%r, extra=%r' % (stdout, extra))
pid = int(stdout.split('\n')[1])
return pid

Expand Down Expand Up @@ -216,6 +208,12 @@ async def test_namespace(self):
self.assertEqual(pids[2], pids[3])
self.assertNotEqual(pids[0], pids[3])

terminal = self.named_tm.terminals["1"]
killed = await terminal.terminate(True)
assert killed
assert not terminal.ptyproc.isalive()
assert terminal.ptyproc.closed

@tornado.testing.gen_test
@pytest.mark.skipif('linux' not in platform, reason='It only works on Linux')
async def test_max_terminals(self):
Expand All @@ -235,6 +233,10 @@ async def test_single_process(self):
pids = await self.get_pids(tms)
self.assertEqual(pids[0], pids[1])

killed = await self.single_tm.terminal.terminate(True)
assert killed
assert self.single_tm.terminal.ptyproc.closed

class UniqueTermTests(TermTestCase):
@tornado.testing.gen_test
async def test_unique_processes(self):
Expand Down