summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/daemon.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 1be89d5b..fc03e3cb 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -143,6 +143,16 @@ def run(client, serial, line):
client.close(fid)
+def adopted_pid(client, pane):
+ """An adopted shell's `echo $$`, once it answers: sized twice at its
+ adoption (dev/Ptys.zig `take`), it draws its prompt again, and a run
+ sent into a prompt redrawn under it reads as not run (core/ninep/pty.zig
+ `noteMarks`)."""
+ wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n')
+ said = run(client, pane, b'echo $$\n')
+ return said.split(b'\n')[1], said
+
+
# FreeBSD has no /proc: ps and procstat answer instead.
procfs = os.path.isdir('/proc/self')
@@ -1528,7 +1538,8 @@ def relink(binary):
before = set(terminals(own))
own.write(f'/pane/{min(before)}/exec', b'Adopt\n')
pane = wait_for('the adopted pane', lambda: set(terminals(own)) - before).pop()
- assert run(own, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode()
+ pid, said = adopted_pid(own, pane)
+ assert pid == str(shell_pid).encode(), (said, shell_pid)
print(f'relink: a client attached to the session through the new daemon; killed outright, its shell {shell_pid} was adopted')
exit_session(own, pane)
stub.wait(timeout=10)
@@ -1602,7 +1613,8 @@ def answer_late(binary):
two.write(f'/pane/{min(before)}/exec', b'Adopt\n')
took = time.monotonic() - asked
pane = wait_for('the adopted pane', lambda: set(terminals(two)) - before).pop()
- assert run(two, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode()
+ pid, said = adopted_pid(two, pane)
+ assert pid == str(shell_pid).encode(), (said, shell_pid)
print(f'answer late: an Adopt asked while the daemon was stopped waited {took:.1f} s for its answer, '
f'and shell {shell_pid} was adopted')
exit_session(two, pane)
@@ -2772,11 +2784,8 @@ def main(binary, cycles):
client.write(f'/pane/{min(before)}/exec', b'Adopt\n')
adopted = wait_for('the adopted pane', lambda: set(terminals(client)) - before)
pane = adopted.pop()
- # Sized twice (Ptys.take): a run into a prompt redrawn under it
- # reads as not run (core/ninep/pty.zig).
- wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n')
- said = run(client, pane, b'echo $$\n')
- assert said.split(b'\n')[1] == str(shell_pid).encode(), said
+ pid, said = adopted_pid(client, pane)
+ assert pid == str(shell_pid).encode(), said
print(f'daemon: shell {shell_pid} outlived kill -9 of its session and was adopted')
# Attached again: a client. (After the runs: a pty/run under a
# client puts it off the session's state, and it joins again; one
@@ -3342,7 +3351,8 @@ def upgrades(old, new):
before = set(terminals(client))
client.write(f'/pane/{min(before)}/exec', b'Adopt\n')
pane = wait_for('the adopted pane', lambda: set(terminals(client)) - before).pop()
- assert run(client, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode()
+ pid, said = adopted_pid(client, pane)
+ assert pid == str(shell_pid).encode(), (said, shell_pid)
print(f'upgrade: the upgraded daemon kept shell {shell_pid} through kill -9 of its session, and it was adopted')
client.write(f'/pane/{pane}/exec', b'Exit\n')
stub.wait(timeout=10)