diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 15:19:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 17:03:40 -0300 |
| commit | f2ede98aee0265e3506f5afd6039c70be7812767 (patch) | |
| tree | 284a64fc9fcf7ba777a20fad75cc6295d70695fb /test/daemon.py | |
| parent | 08c9415dde1a1d5da2c20124c4fcd4c92783b290 (diff) | |
| download | pardes-f2ede98aee0265e3506f5afd6039c70be7812767.tar.gz pardes-f2ede98aee0265e3506f5afd6039c70be7812767.zip | |
remote clients: a pointer's hit carries the place it was made on (Layer.Place, on the wire, version 17) and a step resolves it from that, never from this process's frame (`surface`, `.local`), which a session never draws for a client: a window's pointer over a tag diverged it at once (the user's `tape byte 119`, 15 rejoins in 25 s) and a click there aborted it; a replay that meets a site its tape lacks, or makes a syscall that is none, is a divergence that goes on harmless (poisonOf), not a panic, and a speculation that makes one waits (Tty's shell lookup, untaped, is a value site now, as Shell's was); a copy over a queue is refused, not asserted; a session's last client, while no one else watches it, leaves it its layout (leaveView, settled as closeView is), which its rejoin copies; a redial waits only after an Upgrade's `refused` (a divergence's redialled a gone session 20 s); a dying session shuts its clients' links before its trace, and an --attach client ends its ssh and socket whatever way it exits; a far join's hashing stops at a blob once its client is let go (its leave waits for it in the step); a confirmed speculation's state is checked against its unit's digest, and the trace gives a key's and a pointer's words; test/daemon.py: 200 far joins level, a window's pointer swept over tags and body, ssh stand-in clients refused and detached, a client of a killed session ending in 2 s; in-process tests for each
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 122 |
1 files changed, 120 insertions, 2 deletions
diff --git a/test/daemon.py b/test/daemon.py index 1086dac3..7b0e5343 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -193,7 +193,7 @@ class Replica: """A replica's connection (src/detached/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 16 + WIRE = 17 def __init__(self, path, timeout=10): self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -547,6 +547,11 @@ class Window: self.p.stdin.write(text.replace(b'\x1b', b'\x1b[27u')) self.p.stdin.flush() + def mouse(self, kind, button, x, y): + """A pointer event at window pixels (gui.zig's test feed).""" + self.p.stdin.write(f'\x1b]777;mouse;{kind};{button};{x};{y}\x07'.encode()) + self.p.stdin.flush() + def said(self): return self.err.read_text(errors='replace') if self.err.exists() else '' @@ -632,6 +637,24 @@ def window_clients(binary, gui_binary): n = len(checks(check)) w.keys(b'jjjjjkkk\x06\x06\x02') wait_for(f'the window client agrees again ({rtt} ms)', lambda: agreed(check, n), timeout=30) + if rtt in (0, 207): + # The pointer over the tags (the workspace's, the column's, + # the pane's: the top rows, a test window's cells about 16 by + # 33 pixels) and over the body, a click there: a window's + # hits are its own frame's, which the session never draws, + # so they are its input's, not re-made from a frame. Each + # tag motion made it join again (the user's, 2026-10-30). + n = len(checks(check)) + for y in range(5, 170, 11): + for x in range(4, 1280, 23): + w.mouse('motion', 0, x, y) + for k in range(40): + w.mouse('motion', 0, 100 + 25 * k, 200 + 9 * k) + w.mouse('down', 1, 400, 300) + w.mouse('motion', 1, 600, 360) + w.mouse('up', 1, 600, 360) + wait_for(f'the window client agrees after its pointer ({rtt} ms)', lambda: agreed(check, n), timeout=30) + assert 'joined again' not in w.said(), w.said()[-800:] agreements.append(len(checks(check))) assert w.close() == 0, w.said()[-800:] if relay: @@ -891,6 +914,30 @@ def far(binary): detach('f', tf, f) f_join = joins(root / 'f.stats')[0] assert f_join['from_disk'] > 0 and sum(cached(cache).values()) <= 1 << 20, (f_join, cached(cache)) + far_joins(root / 'pardes-replica.sock', 'files', binary, 200) + # Through ssh (a stand-in forwarding as `ssh -L` does): a client + # refused and one detached each end their ssh and its socket (one + # refused left both, 2026-10-30). + fake = root / 'ssh' + fake.write_text('#!/bin/sh\nwhile [ $# -gt 0 ]; do case $1 in -L) fwd=$2; shift;; esac; shift; done\n' + f'exec {sys.executable} -B {Path(__file__).parent / "delay_relay.py"} "${{fwd%%:*}}" "${{fwd#*:}}" --delay 0\n') + fake.chmod(0o755) + senv = dict(env, PARDES_SSH=str(fake), PARDES_REMOTE_RUNTIME=str(root), TMPDIR=str(root)) + + def forwarded(): + return [q for q in processes(root) if alive(q) and any(b'pardes-ssh-' in a for a in cmdline(q))] or list(root.glob('pardes-ssh-*')) + for name in ('nobody', 'files'): + ts = Term(24, 90) + terms.append(ts) + sc = ts.spawn([binary, f'--attach=box:{name}'], senv) + started.append(sc.pid) + if name == 'files': + wait_for('the client through ssh\'s first frame', lambda: b'line 3 of the notes' in ts.text(), timeout=30) + time.sleep(.3) + os.write(ts.master, b' sD') + wait_for(f'the client through ssh ends ({name})', lambda: sc.poll() is not None, timeout=30) + assert name == 'files' or b"no session called 'nobody'" in ts.text(), ts.text()[-300:] + wait_for(f'its ssh and socket gone ({name})', lambda: not forwarded(), timeout=10) body = texts() for words in (b'from-A', b'from-B', b'again-A', b'from-C', b'from-D', b'from-E', b'from-F'): assert words in body, words @@ -919,6 +966,67 @@ def far(binary): shutil.rmtree(root, ignore_errors=True) +def far_joins(sock, session, binary, n): + """`n` far joins of one session in a row, each read whole (its blobs + asked for by none, its zstd frames unpacked) and answering a ping, then + gone: the session's fds and threads as they were, its RSS within a + bound. Each join made zstd contexts through the C heap, whose release + builds named a new allocator at every malloc and aborted at the 65th + (the box's session, after 15 far joins, 2026-10-30).""" + from compression import zstd + build = semantics(binary) + + def join(): + r = Replica(sock, timeout=30) + name = session.encode() + r.send(0x01, struct.pack('<HQH', Replica.WIRE, build, len(name)) + name) + r.send(0x06, b'\x01') + tag, body = r.read() + assert tag == 0x01, (tag, body) + pid, k = struct.unpack_from('<IH', body) + blobs, = struct.unpack_from('<I', body, len(body) - 4) + if blobs: + r.send(0x07, bytes((blobs + 7) // 8)) + r.send(0x03, struct.pack('<Q', 7)) + d, inner = zstd.ZstdDecompressor(), b'' + while True: + tag, body = r.read() + assert tag == 0x09, tag + inner += d.decompress(body) + while d.eof: + rest, d = d.unused_data, zstd.ZstdDecompressor() + inner += d.decompress(rest) if rest else b'' + while len(inner) >= 5: + t, m = struct.unpack_from('<BI', inner) + if len(inner) < 5 + m: + break + payload, inner = inner[5:5 + m], inner[5 + m:] + if t == 0x03: + assert payload == struct.pack('<Q', 7), payload + r.send(0x02, b'') + r.close() + return pid + + def threads(pid): + return len(os.listdir(f'/proc/{pid}/task')) if procfs else int(ps('-o', 'nlwp=', '-p', str(pid))) + + def rss_kb(pid): + if procfs: + return next(int(line.split()[1]) for line in open(f'/proc/{pid}/status') if line.startswith('VmRSS:')) + return int(ps('-o', 'rss=', '-p', str(pid))) + pid = join() + time.sleep(.5) + before = fds(pid), threads(pid), rss_kb(pid) + t = time.monotonic() + for _ in range(n): + assert join() == pid + wait_for('the far joins\' fds and threads let go', lambda: (fds(pid), threads(pid)) == before[:2], timeout=10) + grown = rss_kb(pid) - before[2] + assert grown < 64 << 10, (before, grown) + print(f'daemon: {n} far joins of one session in {time.monotonic() - t:.1f} s: its fds and threads as they were ' + f'({before[0]}, {before[1]}), its RSS {grown:+d} KB') + + def terminals(client): return [int(row.split()[0]) for row in client.read('/index').splitlines() if row.split()[1] == b'term'] @@ -1014,8 +1122,18 @@ def main(binary, cycles): 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') - # Killed outright: its shells live on, their masters the daemon's. + # 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 + # 20 s and then said only that there was no such session). + tr = Term(24, 90) + rc = tr.spawn([binary, f'--attach={root / "pardes-replica.sock"}:work'], env) + started.append(rc.pid) + wait_for('the replica client\'s first frame', lambda: len(tr.text()) > 2000, timeout=30) os.kill(session, signal.SIGKILL) + killed = time.monotonic() + wait_for('the replica client ended with its session', lambda: rc.poll() is not None, timeout=10) + assert time.monotonic() - killed < 2 and b'let this client go' in tr.text(), (time.monotonic() - killed, tr.text()[-300:]) + tr.close() stub.wait(timeout=10) client.socket.close() term.close() |
