summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 23:28:13 -0300
committerGabriel Schneider <[email protected]>2026-11-17 23:42:48 -0300
commit9b20d00ca5ffbab640b87249d65e4165414d22c1 (patch)
treee62644195d40b5a41ed92a5e19548fa84cff4821 /test
parent6c61169832d6f396ee7a6e9e0b09d9c055d08f8d (diff)
downloadpardes-9b20d00ca5ffbab640b87249d65e4165414d22c1.tar.gz
pardes-9b20d00ca5ffbab640b87249d65e4165414d22c1.zip
replica: a record of a MiB or more crosses to a client by its hash, beside its unit (tape.zig by_hash_min, Big; wire blob): a file over the wire's 16 MiB bound opened while a client was attached was one unit, past the bound, so a Debug session panicked and a release one dropped it, its client diverging at the next unit and joining again to be sent the whole file in the dump; now the read's answer is recorded as the file's BLAKE3, a client on the session's machine reads the path itself and checks it, a far one is sent it in 1 MiB pieces before the unit and keeps it in its cache.xitdb (XDG_CACHE_HOME/pardes), so a far client that joins after is sent none of it; any other record that long (a reload's text, a paste) goes to every client so; test/daemon.py by_hash: a 17 MiB file under a near and a far client, both agree, neither joins again, the near one reads it itself, the far one is sent 8848 KB of zstd and a far client after it none of its 2 blobs; the slot's own BLAKE3 the brief asked for was built and taken out (a hash a kind's open, 7 instructions a byte on the perf build's CPU, for no reader until a client renders kinds); perf --only medium --reps 10 instructions:u 2,459.25M -> 2,459.36M, --terminal-mib 8 3,928.50M -> 3,928.51M; tui core-test 811/950 (139 skipped), shell-test passes, replicas pass (diverged 0, checked/wrong 0), behaviour-test 269/273 (the four addon ABI tests the base fails), --replay 20 seeds 0 failures, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's; headersweep and headersweep-restored failed once at load 14 and pass alone), test/daemon.py passes
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 5c620ba4..c497bb19 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -1096,6 +1096,88 @@ def far(binary):
shutil.rmtree(root, ignore_errors=True)
+def by_hash(binary):
+ """A file over the wire's 16 MiB bound opened while clients are
+ attached (its read was one unit, dropped: the client joined again, a
+ Debug session panicked): it goes by its hash, a client on this machine
+ reading it itself and a far one sent it once, kept on disk; a far client
+ that joins after is sent nothing of it."""
+ scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
+ scratch.mkdir(parents=True, exist_ok=True)
+ root = Path(tempfile.mkdtemp(prefix='rh-', dir=scratch))
+ cache = root / 'cache'
+ 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'),
+ XDG_CACHE_HOME=str(cache), 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(300)))
+ big = root / 'big.txt'
+ with open(big, 'wb') as f:
+ for i in range(17 << 14):
+ f.write(b'%08d %s\n' % (i, os.urandom(27).hex().encode()[:54]))
+ started, terms = [], []
+
+ def client(name, far):
+ t = Term(24, 90)
+ terms.append(t)
+ c = t.spawn([binary, f'--attach={root / "pardes-replica.sock"}:files'],
+ dict(env, PARDES_REPLICA_CHECK=str(root / f'{name}.check'), PARDES_REPLICA_STATS=str(root / f'{name}.stats'),
+ **({'PARDES_REPLICA_FAR': '1'} if far else {})))
+ started.append(c.pid)
+ wait_for(f'client {name}\'s first frame', lambda: b'line 3 of the notes' in t.text(), timeout=30)
+ time.sleep(.3)
+ return t, c
+
+ def read(pid):
+ return next(int(line.split()[1]) for line in open(f'/proc/{pid}/io') if line.startswith('rchar'))
+ try:
+ sess = subprocess.Popen([binary, '--detach=files', str(notes)], env=env, cwd=root, stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
+ started.append(sess.pid)
+ wait_for('the replica socket', (root / 'pardes-replica.sock').exists)
+ wait_for('the session\'s 9P socket', (root / 'pardes-9p-files.sock').exists)
+ nine = Client(root / 'pardes-9p-files.sock')
+ pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text')
+ (ta, a), (tf, f) = client('a', False), client('f', True)
+ seen = {n: len(checks(root / f'{n}.check')) for n in 'af'}
+ was = {c.pid: read(c.pid) for c in (a, f)}
+ nine.write(f'/pane/{pane}/exec', f'Look {big}\n'.encode())
+ for n in 'af':
+ wait_for(f'client {n} agrees with the big file open', lambda: agreed(root / f'{n}.check', seen[n] + 1), timeout=60)
+ assert sess.poll() is None and a.poll() is None and f.poll() is None
+ assert not any(b'joined again' in t.text() for t in (ta, tf))
+ size = big.stat().st_size
+ # This machine's read it from disk; the far one was sent it, zstd.
+ got = {c.pid: read(c.pid) - was[c.pid] for c in (a, f)}
+ assert size <= got[a.pid] < size + (512 << 10), (size, got)
+ assert got[f.pid] < size, (size, got)
+ tg, g = client('g', True)
+ os.write(tg.master, b' sD')
+ wait_for('client G let go', lambda: g.poll() is not None, timeout=20)
+ g_join = joins(root / 'g.stats')[0]
+ assert g_join['from_disk'] == g_join['blobs'] and g_join['sent_kb'] == 0, g_join
+ print(f'daemon: a {size >> 20} MiB file opened under two clients went by its hash: the one on this machine read '
+ f'it itself, the far one was sent {got[f.pid] >> 10} KB and kept it; a far client that joined after was '
+ f'sent none of its {g_join["blobs"]} blobs')
+ for t, c in ((ta, a), (tf, f)):
+ os.write(t.master, b' sD')
+ wait_for('a client let go', lambda: c.poll() is not None, timeout=20)
+ exit_session(nine, pane)
+ sess.wait(timeout=10)
+ nine.socket.close()
+ finally:
+ for t in terms:
+ t.close()
+ for pid in started + processes(root):
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except OSError:
+ pass
+ 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
@@ -1191,6 +1273,7 @@ def main(binary, cycles):
replicas(root, binary, session, daemon)
clients(binary)
far(binary)
+ by_hash(binary)
manage(binary)
shell = terminals(client)[0]
shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1])
@@ -1863,6 +1946,7 @@ if __name__ == '__main__':
manage(sys.argv[2])
elif sys.argv[1:2] == ['--far']:
far(sys.argv[2])
+ by_hash(sys.argv[2])
elif sys.argv[1:2] == ['--window-clients']:
window_clients(sys.argv[2], sys.argv[3])
pdf_window(sys.argv[2], sys.argv[3])