summaryrefslogtreecommitdiff
path: root/test/daemon.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/daemon.py')
-rw-r--r--test/daemon.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 9e9ea600..04455f0f 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -208,6 +208,38 @@ def main(binary, cycles):
assert now == baseline, (cycle, now, baseline)
print(f'daemon: {cycles} detach/attach cycles, fds/sockets/processes level: {baseline}')
+ # Another terminal while one is attached: a view of its own
+ # (src/views.zig), drawn beside the first. Detached from inside, its
+ # stub ends and the first draws on; closed outright, the same.
+ for how in ('detach', 'close'):
+ term2 = Term(20, 60)
+ stub2 = term2.spawn([binary, '--attach=work'], env)
+ started.append(stub2.pid)
+ wait_for('the second terminal\'s first frame', lambda: b'\x1b[?1049h' in term2.text())
+ wait_for('the second terminal\'s view live', lambda: client.screen()['cols'] == 60)
+ seen = len(term.text())
+ run(client, shell, f'echo both-drawn-{how}\n'.encode())
+ wait_for('the first terminal drawn', lambda: f'both-drawn-{how}'.encode() in term.text()[seen:])
+ wait_for('the second terminal drawn', lambda: f'both-drawn-{how}'.encode() in term2.text())
+ assert stub.poll() is None and stub2.poll() is None
+ if how == 'detach':
+ # Its view is the live one (its terminal spoke last).
+ client.write(f'/pane/{shell}/exec', b'Detach\n')
+ assert stub2.wait(timeout=10) == 0, stub2.returncode
+ assert b'detached from \'work\'' in term2.text(), term2.text()[-400:]
+ term2.close()
+ else:
+ term2.close()
+ assert stub2.wait(timeout=10) != 0 or True
+ wait_for('the first terminal\'s view live again', lambda: client.screen()['cols'] == 100)
+ seen = len(term.text())
+ run(client, shell, f'echo first-on-{how}\n'.encode())
+ wait_for('the first terminal drawn on', lambda: f'first-on-{how}'.encode() in term.text()[seen:])
+ assert stub.poll() is None, 'the first terminal stays attached'
+ now = (fds(session), fds(daemon), len(list(root.iterdir())), len([p for p in processes(root) if alive(p)]))
+ assert now[:3] == baseline[:3], (how, now, baseline)
+ print('daemon: a second terminal on an attached session drawn beside the first, then detached and closed; the first drew on')
+
# Killed outright: its shells live on, their masters the daemon's.
os.kill(session, signal.SIGKILL)
stub.wait(timeout=10)