summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 22:56:07 -0300
committerGabriel Schneider <[email protected]>2026-10-29 23:37:00 -0300
commit370913ae34c69b7958911c6146612c77275f6ebf (patch)
tree61e4fd328e104afbb381d2fd161029d1be637aa7 /test
parentddcfd860ef05c37f5536038d8828cc81c0c4125c (diff)
downloadpardes-370913ae34c69b7958911c6146612c77275f6ebf.tar.gz
pardes-370913ae34c69b7958911c6146612c77275f6ebf.zip
upgrade: a newer build at the path a session started from is said at a focus-in, once a build, the path read just after the first frame (off a startup's way); an upgraded process lets the binary it replaced go (held, its deleted file kept its blocks) and sweeps its old image's prompt files (kept for an exec that failed); test/daemon.py --upgrade asks through /ctl, checks the fds and prompt files level, and runs on FreeBSD (procstat, the daemon's registry, no kept old binary there)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py94
1 files changed, 65 insertions, 29 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 7d35e427..ce19b502 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -549,10 +549,11 @@ def saying(sock, words, timeout=30):
def exe_of(pid):
"""What /proc says the process runs: (its path, whether that file is the
- one at the path now)."""
- link = os.readlink(f'/proc/{pid}/exe') if procfs else ps('-o', 'comm=', '-p', str(pid)).decode().strip()
+ one at the path now). FreeBSD's procstat names the path alone."""
if not procfs:
- return link, True
+ rows = subprocess.run(['procstat', '-b', str(pid)], capture_output=True).stdout.decode().splitlines()
+ return (rows[-1].split()[-1] if len(rows) > 1 else ''), None
+ link = os.readlink(f'/proc/{pid}/exe')
try:
same = os.stat(f'/proc/{pid}/exe').st_ino == os.stat(link).st_ino
except OSError:
@@ -570,7 +571,10 @@ def install(binary, at):
"""As `zig build` and install(1) put a build in place: a new file
renamed over the old, which a process running it keeps, deleted."""
tmp = at.with_name(at.name + '.new')
- subprocess.run(['cp', '--reflink=auto', os.fspath(binary), os.fspath(tmp)], check=True)
+ if procfs:
+ subprocess.run(['cp', '--reflink=auto', os.fspath(binary), os.fspath(tmp)], check=True)
+ else:
+ shutil.copyfile(binary, tmp)
os.chmod(tmp, 0o755)
os.replace(tmp, at)
@@ -627,18 +631,45 @@ def upgrades(old, new):
before = len(term.text()), len(term2.text())
install(new, binary)
- assert exe_of(session)[1] is False, 'the session runs the old build, deleted'
- client.write(f'/pane/{shell}/exec', b'Upgrade\n')
+ assert not procfs or exe_of(session)[1] is False, 'the session runs the old build, deleted'
+ # Come back to the terminal: the newer build is said.
+ os.write(term.master, b'\x1b[I')
+ wait_for('the newer build said', lambda: 'a newer pardes is installed' in screen_text(client))
+ fds_before = fds(session), fds(daemon)
+ rcs = sorted(Path('/tmp').glob(f'pardes-osc133-*-{session}-*'))
+ t = time.monotonic()
+ client.write('/ctl', b'Upgrade\n')
client.socket.close()
- wait_for('the session on the new build', lambda: exe_of(session) == (str(binary), True), timeout=30)
+ new_build = semantics(new)
+ assert new_build != old_build
+ if procfs:
+ wait_for('the session on the new build', lambda: exe_of(session) == (str(binary), True), timeout=30)
+ else:
+ wait_for('the session registered as the new build',
+ lambda: Replica(root / 'pardes-replica.sock').hello('work', new_build)[0] == 'welcome', timeout=30)
client = reconnect(sock)
+ took = time.monotonic() - t
assert int(dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines())['pid']) == session
- wait_for('the daemon on the new build', lambda: exe_of(daemon) == (str(binary), True))
+ if procfs:
+ wait_for('the daemon on the new build', lambda: exe_of(daemon) == (str(binary), True))
+ else:
+ wait_for('the daemon exec\'d again', lambda: any(a.startswith(b'--upgraded=') for a in cmdline(daemon)))
assert alive(daemon) and stub.poll() is None and stub2.poll() is None
# A replica of the old build is told why it is let go.
tag, body = replica.read()
assert tag == 0x02 and b'upgrading to another build' in body, (tag, body)
replica.close()
+ # The old image's prompt files swept, the new one's made.
+ wait_for('the prompt files level', lambda: len(list(Path('/tmp').glob(f'pardes-osc133-*-{session}-*'))) == len(rcs))
+ assert sorted(Path('/tmp').glob(f'pardes-osc133-*-{session}-*')) != rcs or not rcs
+ # Nothing kept that was not: the old binary let go, every fd back.
+ # (The replica's connection is the one fewer.)
+ level = fds_before[0] - 1, fds_before[1]
+ try:
+ wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level, timeout=5)
+ except TimeoutError:
+ raise AssertionError(('fds', level, (fds(session), fds(daemon)),
+ os.listdir(f'/proc/{session}/fd') if procfs else None))
# The edit and its undo.
assert client.read(f'/pane/{text}/body') == b'one\ntwo\nunsaved\n'
assert any(row.split()[0] == str(text).encode() and row.split()[2] == b'1' for row in client.read('/index').splitlines()), client.read('/index')
@@ -651,37 +682,39 @@ def upgrades(old, new):
wait_for('the second terminal redrawn', lambda: b'\x1b[?1049h' in term2.text()[before[1]:])
wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client))
# The daemon lists the session under its new build.
- new_build = semantics(new)
- assert new_build != old_build
said = Replica(root / 'pardes-replica.sock').hello('work', new_build)
assert said == ('welcome', session, 'work'), said
said = Replica(root / 'pardes-replica.sock').hello('work', old_build)
assert said[0] == 'refused' and 'another build' in said[1], said
os.kill(sleeper, signal.SIGTERM)
wait_for('the shell carrying on', lambda: b'done-after-upgrade\n' in client.read(f'/pane/{shell}/body'))
- print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and two terminals on the new build; '
- 'the edit, its undo and the job kept')
+ print(f'upgrade: session {session}, its daemon {daemon}, shell {shell_pid} and two terminals on the new build '
+ f'(the word to its 9P again: {took * 1000:.0f} ms); the edit, its undo and the job kept')
- # A build that cannot load the dump: back to the one running.
+ # A build that cannot load the dump: back to the one running (a copy
+ # of it kept open from /proc/self/exe; FreeBSD keeps none).
refuser = root / 'refuser'
- refuser.write_text('#!/bin/sh\n# A pardes whose load refuses the dump (upgrade.zig).\n'
- f'case "$1" in --upgraded=*) PARDES_TEST_UPGRADE_REFUSE=1 exec {new} "$@";; esac\n'
- f'exec {new} "$@"\n')
- refuser.chmod(0o755)
- running = os.stat(f'/proc/{session}/exe').st_ino
- install(refuser, binary)
- client.write(f'/pane/{shell}/exec', b'Upgrade\n')
- client.socket.close()
- client = saying(sock, 'it goes on as')
- 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()
- print('upgrade: a build that refused the dump fell back to the one running; the shell ran on')
+
+ def refusing(how):
+ refuser.write_text('#!/bin/sh\n# A pardes whose load refuses the dump (upgrade.zig).\n'
+ f'case "$1" in --upgraded=*) PARDES_TEST_UPGRADE_REFUSE={how} exec {new} "$@";; esac\n'
+ f'exec {new} "$@"\n')
+ refuser.chmod(0o755)
+ install(refuser, binary)
+ if procfs:
+ running = os.stat(f'/proc/{session}/exe').st_ino
+ refusing('1')
+ client.write(f'/pane/{shell}/exec', b'Upgrade\n')
+ client.socket.close()
+ client = saying(sock, 'it goes on as')
+ 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()
+ 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.
- refuser.write_text(refuser.read_text().replace('=1 exec', '=all exec'))
- install(refuser, binary)
+ refusing('all')
client.write(f'/pane/{shell}/exec', b'Upgrade\n')
client.socket.close()
client = saying(sock, 'brings the rest back')
@@ -712,6 +745,9 @@ def upgrades(old, new):
wait_for('the next session', sock.exists)
client = Client(sock)
started.append(int(dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines())['pid']))
+ # Its reader of the daemon starts after its first frame: an Adopt
+ # before that waits for an `ok` nobody reads, and is refused.
+ wait_for('the next session\'s first frame', lambda: b'\x1b[?1049h' in term.text())
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()