diff options
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/test/daemon.py b/test/daemon.py index f8ef9be4..c53405db 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -1139,9 +1139,11 @@ 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. + # Another terminal while one is attached: a replica client of the + # session (a session shows one frontend of its own), listed under + # it by --ps, drawn beside the first, typed into as the first is. + # Detached from inside, it ends and the first draws on; closed + # outright, the same. for how in ('detach', 'close'): # Bigger than the first: the shell, sized for the first (its # last typist), shows whole in it. @@ -1150,6 +1152,12 @@ def main(binary, cycles): 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'] == 120) + listed = subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode() + assert f'client {stub2.pid} ' in listed, listed + os.write(term.master, f'echo one-typed-{how}\r'.encode()) + wait_for('the first terminal\'s keys in the shell', lambda: f'one-typed-{how}'.encode() in client.read(f'/pane/{shell}/body')) + os.write(term2.master, f'echo two-typed-{how}\r'.encode()) + wait_for('the second terminal\'s keys in the shell', lambda: f'two-typed-{how}'.encode() in client.read(f'/pane/{shell}/body')) 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:]) @@ -1158,20 +1166,20 @@ def main(binary, cycles): 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 - wait_for('the second stub says it detached', lambda: b'detached from \'work\'' in term2.text()) + stub2.wait(timeout=10) term2.close() else: term2.close() stub2.wait(timeout=10) wait_for('the first terminal\'s view live again', lambda: client.screen()['cols'] == 100) + wait_for('the client gone from --ps', lambda: 'client ' not in subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode()) 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') + print('daemon: a second terminal on an attached session a client of it (in --ps), both typed into and drawn, then detached and closed; the first drew on') # Killed outright: its shells live on, their masters the daemon's, # and a replica client of it hears so at once, in words (one froze @@ -1302,17 +1310,18 @@ def gui(binary, cycles): baseline = baseline or now assert now == baseline, (cycle, now, baseline) print(f'daemon: {cycles} window detach/attach cycles, fds/processes level: {baseline}') - # Attached already: another window, a view of its own (its test - # captures under view-1); Detach in it closes only it. - attach = subprocess.run([binary, '--attach=win'], env=env, cwd=root, timeout=10, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - assert attach.returncode == 0, attach.stderr - wait_for('the second window drawn', lambda: (root / 'caps' / 'view-1' / 'latest.ppm').exists()) - client.write(f'/pane/{shell}/exec', b'Detach\n') - time.sleep(.5) + # Attached already: another window is a replica client of the + # session (its own process, its captures its own), listed by --ps; + # closed, it ends alone. + second = Window(root, 'second', [binary, '--attach=win'], env) + wait_for('the second window drawn', lambda: (root / 'second' / 'latest.ppm').exists(), timeout=20) + listed = subprocess.run([binary, '--ps'], env=env, cwd=root, capture_output=True, timeout=30).stdout.decode() + assert f'client {second.pid} ' in listed, listed + second.close() + wait_for('the client gone from --ps', lambda: 'client ' not in subprocess.run([binary, '--ps'], env=env, cwd=root, capture_output=True, timeout=30).stdout.decode()) assert not sized(client), 'the first window stays' assert proc.poll() is None - print('daemon: a second window on an attached window session, detached alone') + print('daemon: a second window on an attached window session a client of it (in --ps), closed alone') # Another kind joins as a replica client: a terminal of the window's # session, by its name alone. A name nobody has is refused in words. client.write(f'/pane/{shell}/exec', b'Detach\n') |
