diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 01:34:10 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 01:51:21 -0300 |
| commit | 63f59cbf3092c8bb7e3eae155969c0249fe2063d (patch) | |
| tree | 09b8e3631b3e7797e597124dedb284f09f2d8cd7 /test | |
| parent | 6d937cd125ca04a2edb92b2d014014ee6c2eb45d (diff) | |
| download | pardes-63f59cbf3092c8bb7e3eae155969c0249fe2063d.tar.gz pardes-63f59cbf3092c8bb7e3eae155969c0249fe2063d.zip | |
replica: an attach handed to a session as it upgrades is told so and joins the new process, never cut unanswered by the exec: `Peers.refuseAll` returned at once when no client was joined, and with clients its `drop` closed the connections queued in `Peers.inbox` without a word, and a hand-over posted after it was closed by the exec (MSG_CMSG_CLOEXEC), so `pardes attach NAME` started as NAME upgraded said "the session hung up before the dump was whole" and exited 1, with PARDES_PAIR or without (exp2: a `new --detach` session, no variable, ReleaseSafe main: 2 of 20 attaches at 0 ms); now refuseAll tells each queued connection what it tells its clients (`replica.upgrading`, "the session is upgrading to another build of pardes", the words tui and gui passed), `Peers.upgrading` makes `post` tell a later hand-over the same at once (reset at the next boundary: the exec failed), and a first join told so dials again patiently (`join` -> `redial`, its view optional); the pair row that failed on the release build only (daemon.py --pair, `ended_by(how, *attached('rows'))`, the coordinator's landing check) was this race, reached through the test: its `upgraded()` waited for `--upgraded=` in the session's command line, which a second Upgrade's old process already had, so it attached to the old process; found under strace (the daemon handed the attach, then took the session's `upgrade`, then exec'd); the release build and the test's long runtime path only moved the timing; `upgraded()` now waits for the session's 9P socket made anew; tests: core/replica.zig "an Upgrade tells a client handed to the session and not joined yet that it is upgrading ..." (main: both hand-overs still queued, never told), test/daemon.py `attach_upgrading` (plain, --pair, --attach-upgrading: an attach started 0-25 ms after the Upgrade's word, without the variable and with it: main's release build failed its first round)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/test/daemon.py b/test/daemon.py index 44221d17..d3ba6e3d 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -29,6 +29,8 @@ private HOME and runtime directory: `pardes new --detach` returns once its session runs python3 -B test/daemon.py --pair <pardes> PARDES_PAIR: a terminal's session and its first client + python3 -B test/daemon.py --attach-upgrading <pardes> + an attach started as its session upgrades (in plain and --pair too) python3 -B test/daemon.py --relink <pardes> the daemon killed: its sessions register again with the next; and one stopped: an Adopt waits for its answer to the hello @@ -748,9 +750,12 @@ def pair_rows(binary): def upgraded(name, nine, session): """An Upgrade to the same build: the session exec'd under its pid, its - 9P again.""" + 9P again: its socket made anew (a second Upgrade's command line says + `--upgraded=` before its exec too).""" + sock = root / f'pardes-9p-{name}.sock' + before = sock.stat().st_ino nine.write('/ctl', b'Upgrade\n') - wait_for('the session exec\'d', lambda: any(a.startswith(b'--upgraded=') for a in cmdline(session)), timeout=60) + wait_for('the session exec\'d', lambda: sock.stat().st_ino != before, timeout=60) nine.socket.close() again = reconnect(root / f'pardes-9p-{name}.sock') assert alive(session) @@ -863,6 +868,63 @@ def pair_rows(binary): shutil.rmtree(root, ignore_errors=True) +def attach_upgrading(binary, rounds=6): + """`pardes attach` as its session upgrades: started at once after the + Upgrade's word, it is handed to the session before the exec; told the + session is upgrading (never cut by the exec unanswered: "hung up before + the dump was whole", exit 1), it dials again and joins the new process. + A `new --detach` session, without the variable and with it.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='ru-', dir=scratch)) + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(30))) + terms = [] + try: + for e in (env, dict(env, PARDES_PAIR='1')): + name = 'up' + e.get('PARDES_PAIR', '') + out = subprocess.run([binary, 'new', f'--detach={name}', str(notes)], env=e, cwd=root, capture_output=True, + timeout=30, stdin=subprocess.DEVNULL) + assert out.returncode == 0, out + sock = root / f'pardes-9p-{name}.sock' + nine = Client(sock) + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + for k in range(rounds): + before = sock.stat().st_ino + nine.write('/ctl', b'Upgrade\n') + time.sleep(k * .005) + t = Term(30, 100) + terms.append(t) + a = t.spawn([binary, 'attach', name], e) + wait_for('the client drawn, or gone', lambda: b'line 3 of the notes' in t.text() or a.poll() is not None, timeout=40) + assert a.poll() is None, (k, a.returncode, t.text()[-120:]) + os.kill(a.pid, signal.SIGKILL) + a.wait(timeout=10) + wait_for('the session exec\'d', lambda: sock.stat().st_ino != before, timeout=60) + nine.socket.close() + nine = reconnect(sock) + assert alive(session) + nine.socket.close() + assert subprocess.run([binary, 'kill', name], env=e, capture_output=True, timeout=30).returncode == 0 + wait_for('the session ended', lambda: not alive(session), timeout=30) + print(f'attach upgrading: an attach started as its session upgrades joins the new process ({rounds} of {rounds}, ' + 'without the variable and with it)') + finally: + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + for t in terms: + t.close() + shutil.rmtree(root, ignore_errors=True) + + def manage(binary): """`pardes --ps`, `--kill=NAME` and `--kill-all`: two detached sessions and their shells listed, one session killed outright and its shell @@ -2069,6 +2131,7 @@ def main(binary, cycles): launch(binary) pair(binary) pair_rows(binary) + attach_upgrading(binary) manage(binary) relink(binary) answer_late(binary) @@ -3022,6 +3085,9 @@ if __name__ == '__main__': elif sys.argv[1:2] == ['--pair']: pair(sys.argv[2]) pair_rows(sys.argv[2]) + attach_upgrading(sys.argv[2]) + elif sys.argv[1:2] == ['--attach-upgrading']: + attach_upgrading(sys.argv[2]) elif sys.argv[1:2] == ['--relink']: relink(sys.argv[2]) answer_late(sys.argv[2]) |
