summaryrefslogtreecommitdiff
path: root/test/daemon.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 09:16:01 -0300
committerGabriel Schneider <[email protected]>2026-11-23 10:58:26 -0300
commitffc4f307ff330a8b13aa5c19df079e4664a573a2 (patch)
treeb31df7fd28660dd55e80d51ee6a0efd4f5b766da /test/daemon.py
parent9a648ef09bb32f42fb6b09bebbe8c851be360c6e (diff)
downloadpardes-ffc4f307ff330a8b13aa5c19df079e4664a573a2.tar.gz
pardes-ffc4f307ff330a8b13aa5c19df079e4664a573a2.zip
test/daemon.py, test/process: a shell's first pty/run asked once, at once, its whole answer said when it is not what the row wants: `gui_upgrades`' setup failed twice this week on `int(b'')`, the answer never shown (it was `error not run`, the product's, the change before); now every first `echo $$` after a start is test/daemon.py `pid_in` (`exit 0` and a pid, or an AssertionError naming the pane and the answer whole), which replaces `adopted_pid` and the waits that stood in for the product's (a `true` run again until it answered `exit 0`): manage and relink (a session's Term), relink, answer_late, main, upgrades, upgrade_clients and gui_upgrades (a session's first terminal), upgrades (the run after the fallback, the fresh session's terminals), and the four adopted shells (relink, answer_late, main, upgrades); clients' first run in its new Term checks its answer; test/process: terminals.zig's `prompted` (a `true`-until-`exit 0` loop) deleted, sized's first run (`stty size`) asked at once, runFile's `while busy` loop ("deadline its first prompt": the greeting's `ls`) one run that must answer `exit 0`, look_and_exec.zig's `true`-until-`exit 0` loop one run; kept: terminals.zig's wait for a restarted shell (a run written at once can still reach the shell being replaced) and look_and_exec's for the shell back after `cat`; with the product change before: tui process-test 0 of 146 (load 6.2), test/daemon.py on ReleaseSafe plain 1/1, `--upgrade` from the installed build 1/1, `--upgrade --gui` from the installed build 5/5, `--relink` 20 of 20 (on the installed build 18 of 20 (two `error not run` on the adopted shell), each failure `AssertionError: pane 3: `echo $$` answered b'error not run\n'`: what adopted_pid's wait hid)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/daemon.py')
-rw-r--r--test/daemon.py55
1 files changed, 26 insertions, 29 deletions
diff --git a/test/daemon.py b/test/daemon.py
index dc1abcbc..ca59449c 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -188,14 +188,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')
+def pid_in(client, pane):
+ """The pid of terminal `pane`'s shell, its `echo $$` by pty/run, asked
+ at once: a run written before its first prompt (or before the prompt
+ after its greeting) waits for it, and one under a prompt drawn again
+ (a window's first size, an adoption's two) is still the line run
+ (core/ninep/pty.zig). Any other answer is said whole."""
said = run(client, pane, b'echo $$\n')
- return said.split(b'\n')[1], said
+ pid = re.fullmatch(rb'exit 0\n([0-9]+)\n', said)
+ assert pid, f'pane {pane}: `echo $$` answered {said!r}'
+ return int(pid[1])
# FreeBSD has no /proc: ps and procstat answer instead.
@@ -580,7 +582,8 @@ def clients(binary):
c = tc.spawn([binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_CHECK=str(root / 'c.check')))
started.append(c.pid)
wait_for('client C\'s first frame', lambda: b'$' in tc.text(), timeout=20)
- run(nine, shell, b'echo from-the-session\n')
+ said = run(nine, shell, b'echo from-the-session\n')
+ assert said == b'exit 0\nfrom-the-session\n', said
os.write(tc.master, b'echo from-C\r')
wait_for('client C\'s keys in the shell', lambda: b'from-C' in nine.read(f'/pane/{shell}/body'))
wait_for('client C agrees with a shell\'s output', lambda: agreed(root / 'c.check', 0))
@@ -1458,8 +1461,7 @@ def manage(binary):
c.write('/pane/1/exec', b'Term\n')
wait_for(f'session {name}\'s shell', lambda: terminals(c))
shell = terminals(c)[0]
- wait_for(f'session {name}\'s shell answers', lambda: run(c, shell, b'true\n') == b'exit 0\n')
- shells[name] = int(run(c, shell, b'echo $$\n').split(b'\n')[1])
+ shells[name] = pid_in(c, shell)
started.append(shells[name])
daemon = [p for p in processes(root) if cmdline(p)[1:2] == [b'--daemon']][0]
started.append(daemon)
@@ -1563,8 +1565,7 @@ def relink(binary):
work.write('/pane/1/exec', b'Term\n')
wait_for('its shell', lambda: terminals(work))
shell = terminals(work)[0]
- wait_for('its shell answers', lambda: run(work, shell, b'true\n') == b'exit 0\n')
- shell_pid = int(run(work, shell, b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(work, shell)
started.append(shell_pid)
term = Term()
terms.append(term)
@@ -1576,7 +1577,7 @@ def relink(binary):
started.append(own_pid)
wait_for('its first frame', lambda: b'\x1b[?1049h' in term.text())
own_shell = terminals(own)[0]
- own_shell_pid = int(run(own, own_shell, b'echo $$\n').split(b'\n')[1])
+ own_shell_pid = pid_in(own, own_shell)
started.append(own_shell_pid)
expected = [f'session work {session} {listed_as("detached")}', f'session own {own_pid} {listed_as("has a frontend")}',
f'shell {shell_pid}', f'shell {own_shell_pid}']
@@ -1608,8 +1609,7 @@ 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()
- pid, said = adopted_pid(own, pane)
- assert pid == str(shell_pid).encode(), (said, shell_pid)
+ assert (pid := pid_in(own, pane)) == shell_pid, (pid, 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)
@@ -1659,7 +1659,7 @@ def answer_late(binary):
one = Client(root / 'pardes-9p-one.sock')
session = int(dict(line.split(maxsplit=1) for line in one.read('/status').decode().splitlines())['pid'])
started.append(session)
- shell_pid = int(run(one, terminals(one)[0], b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(one, terminals(one)[0])
started.append(shell_pid)
daemon = [p for p in processes(root) if cmdline(p)[1:2] == [b'--daemon']][0]
started.append(daemon)
@@ -1683,8 +1683,7 @@ 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()
- pid, said = adopted_pid(two, pane)
- assert pid == str(shell_pid).encode(), (said, shell_pid)
+ assert (pid := pid_in(two, pane)) == shell_pid, (pid, 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)
@@ -2833,7 +2832,7 @@ def main(binary, cycles):
answer_late(binary)
kitty_image(binary)
shell = terminals(client)[0]
- shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(client, shell)
started.append(shell_pid)
# Detach in the terminal it was born with: the stub ends (exit 0,
# its words), the terminal put back; the session runs on detached,
@@ -2974,8 +2973,7 @@ 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()
- pid, said = adopted_pid(client, pane)
- assert pid == str(shell_pid).encode(), said
+ assert (pid := pid_in(client, pane)) == shell_pid, (pid, shell_pid)
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
@@ -3382,7 +3380,7 @@ def upgrades(old, new):
daemon = wait_for('the daemon', lambda: [p for p in processes(root) if cmdline(p)[1:2] == [b'--daemon']])[0]
started.append(daemon)
shell = terminals(client)[0]
- shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(client, shell)
started.append(shell_pid)
client.write(f'/pane/{shell}/look', f'{notes}\n'.encode())
text = int(client.read('/look'))
@@ -3572,7 +3570,7 @@ def upgrades(old, new):
assert os.stat(f'/proc/{session}/exe').st_ino == running, 'back on the build that ran'
assert alive(shell_pid) and ppid(shell_pid) == session and stub.poll() is None
assert client.read(f'/pane/{text}/body') == b'one\ntwo\n'
- assert run(client, shell, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode()
+ assert (pid := pid_in(client, shell)) == shell_pid, (pid, shell_pid)
print('upgrade: a build that refused the dump fell back to the one running; the shell ran on')
# One that refuses it everywhere: a fresh session, the shells adopted.
@@ -3585,8 +3583,8 @@ def upgrades(old, new):
kept = client.read('/dumps').decode()
assert any(line.split()[0].startswith(f'upgrade-{session}') for line in kept.splitlines()), kept
assert alive(shell_pid) and ppid(shell_pid) == session, ('the shell under the fresh session', shell_pid, alive(shell_pid) and ppid(shell_pid), session)
- pids = {p: run(client, p, b'echo $$\n') for p in terminals(client)}
- adopted = [p for p, out in pids.items() if out.split(b'\n')[1:2] == [str(shell_pid).encode()]]
+ pids = {p: pid_in(client, p) for p in terminals(client)}
+ adopted = [p for p, pid in pids.items() if pid == shell_pid]
assert adopted, ('the shell is a pane of the fresh session', shell_pid, pids, client.read('/index'))
print(f'upgrade: a build that refused it everywhere started afresh, shell {shell_pid} adopted, the dump kept')
@@ -3623,8 +3621,7 @@ 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()
- pid, said = adopted_pid(client, pane)
- assert pid == str(shell_pid).encode(), (said, shell_pid)
+ assert (pid := pid_in(client, pane)) == shell_pid, (pid, shell_pid)
print(f'upgrade: the upgraded daemon kept shell {shell_pid} through kill -9 of its session, and it was adopted')
exit_session(client, pane)
stub.wait(timeout=10)
@@ -3723,7 +3720,7 @@ def upgrade_clients(old, new):
nine = Client(sock)
session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid'])
shell = terminals(nine)[0]
- shell_pid = int(run(nine, shell, b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(nine, shell)
t = Term(30, 100)
terms.append(t)
tc = t.spawn([str(binary), 'attach', 'up'], dict(env, PARDES_REPLICA_CHECK=str(root / 't.check')))
@@ -3828,7 +3825,7 @@ def gui_upgrades(old, new):
daemon = wait_for('the daemon', lambda: [p for p in processes(root) if cmdline(p)[1:2] == [b'--daemon']])[0]
started.append(daemon)
shell = terminals(client)[0]
- shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1])
+ shell_pid = pid_in(client, shell)
started.append(shell_pid)
client.write(f'/pane/{shell}/look', f'{notes}\n'.encode())
text = int(client.read('/look'))