diff options
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/test/daemon.py b/test/daemon.py index 44221d17..37487a99 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -33,7 +33,8 @@ private HOME and runtime directory: the daemon killed: its sessions register again with the next; and one stopped: an Adopt waits for its answer to the hello 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) @@ -241,7 +242,7 @@ class Replica: """A replica's connection (abi/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 = 25 + WIRE = 26 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout @@ -1640,6 +1641,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 @@ -3029,6 +3105,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]) far_find(sys.argv[2]) elif sys.argv[1:2] == ['--far-find']: |
