summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 21:23:20 -0300
committerGabriel Schneider <[email protected]>2026-11-21 00:59:00 -0300
commit1388d776ae759796884b9faa106b1c9c222eefa9 (patch)
tree5cc6dd2b5d32d399feae4290d6eb6609c38b639e /test
parente3683f64710e363cb666f61d069e43324dd0f188 (diff)
downloadpardes-1388d776ae759796884b9faa106b1c9c222eefa9.tar.gz
pardes-1388d776ae759796884b9faa106b1c9c222eefa9.zip
daemon.py --far: far_flood, a far client across delay_relay.py at 200 ms each way and 20 KB/s while the session's shell runs yes: it agrees once yes ends and its keys go in; owed since step 3 of the terminals' line as the lag bound through a real pair, but a real client on screen state pulls its terminal's screen, so a flood does not queue for it: at 1 Mbit/s and at 20 KB/s it never fell behind_max_ms behind (two runs), and a join for its lag is not asserted; --far passes whole
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py79
1 files changed, 78 insertions, 1 deletions
diff --git a/test/daemon.py b/test/daemon.py
index de586895..11c98cd6 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -32,7 +32,8 @@ private HOME and runtime directory:
python3 -B test/daemon.py --relink <pardes>
the daemon killed: its sessions register again with the next
python3 -B test/daemon.py --far <pardes>
- the far clients and their blob cache alone, and a file by its hash
+ the far clients and their blob cache alone, one under `yes` across
+ a slow link, and a file by its hash
python3 -B test/daemon.py --games <pardes> <lib> [seconds]
the games in the clients that show them, from zig build
addon-test's <prefix>/lib (libsnake, liblife, libliar)
@@ -1465,6 +1466,81 @@ def far(binary):
shutil.rmtree(root, ignore_errors=True)
+def far_flood(binary):
+ """A far client (PARDES_REPLICA_FAR) across a slow link (delay_relay.py:
+ 200 ms each way, 20 KB/s) while the session's shell runs `yes`: once
+ `yes` ends it agrees with the session, and its keys after go in. It
+ pulls its terminal's screen (screen state), so the flood does not
+ queue for it: it keeps up without joining again (two runs, 2026-11-20),
+ and replica.behind_max_ms is not reached this way."""
+ scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
+ scratch.mkdir(parents=True, exist_ok=True)
+ root = Path(tempfile.mkdtemp(prefix='fl-', dir=os.environ.get('TMPDIR') or 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'),
+ XDG_CACHE_HOME=str(root / '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)))
+ started = []
+ terms = []
+ 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)
+ sock = root / 'pardes-replica.sock'
+ wait_for('the replica socket', 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')
+ nine.write(f'/pane/{pane}/exec', b'Term\n')
+ shell = wait_for('a shell pane', lambda: next((int(row.split()[0]) for row in nine.read('/index').splitlines()
+ if row.split()[1] == b'term'), None))
+ wait_for('the shell\'s prompt', lambda: b'$' in nine.read(f'/pane/{shell}/body') or b'#' in nine.read(f'/pane/{shell}/body'))
+ relay = subprocess.Popen([sys.executable, '-B', str(Path(__file__).parent / 'delay_relay.py'),
+ str(root / 'relay.sock'), str(sock), '--delay', '200', '--rate', '0.02'],
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ started.append(relay.pid)
+ wait_for('the relay', (root / 'relay.sock').exists)
+ check = root / 'f.check'
+ t = Term(30, 100)
+ terms.append(t)
+ c = t.spawn([binary, f'--attach={root / "relay.sock"}:files'],
+ dict(env, PARDES_REPLICA_FAR='1', PARDES_REPLICA_CHECK=str(check)))
+ started.append(c.pid)
+ wait_for('the far client\'s first frame', lambda: b'line 3 of the notes' in t.text(), timeout=60)
+ nine.write(f'/pane/{shell}/pty/data', b'timeout 20 yes; echo yes-done\r')
+ wait_for('yes ended', lambda: b'yes-done' in nine.read(f'/pane/{shell}/body').replace(b'\r', b''), timeout=60)
+ seen = len(checks(check))
+ wait_for('the far client agrees once yes ended', lambda: agreed(check, seen), timeout=120)
+ os.write(t.master, b'echo from-far\r')
+ wait_for('the far client\'s keys in the shell', lambda: b'from-far' in nine.read(f'/pane/{shell}/body'), timeout=30)
+ seen = len(checks(check))
+ wait_for('the far client agrees after its keys', lambda: agreed(check, seen), timeout=60)
+ # Its keys go to the shell: its terminal hangs up instead.
+ c.send_signal(signal.SIGHUP)
+ c.wait(timeout=10)
+ print(f'daemon: a far client across 20 KB/s and 200 ms each way under `yes` agreed once it ended '
+ f'({len(checks(check))} checks) and its keys went in')
+ relay.kill()
+ relay.wait()
+ exit_session(nine, pane)
+ sess.wait(timeout=60)
+ nine.socket.close()
+ wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=10)
+ finally:
+ for term in terms:
+ term.close()
+ for pid in started + processes(root):
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except OSError:
+ pass
+ 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
@@ -2490,6 +2566,7 @@ if __name__ == '__main__':
games(sys.argv[2], sys.argv[3], float(sys.argv[4]) if len(sys.argv) > 4 else 10)
elif sys.argv[1:2] == ['--far']:
far(sys.argv[2])
+ far_flood(sys.argv[2])
by_hash(sys.argv[2])
elif sys.argv[1:2] == ['--window-clients']:
window_clients(sys.argv[2], sys.argv[3])