diff options
Diffstat (limited to 'test/daemon.py')
| -rw-r--r-- | test/daemon.py | 179 |
1 files changed, 117 insertions, 62 deletions
diff --git a/test/daemon.py b/test/daemon.py index 2e666ad1..55cffaf4 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -69,12 +69,6 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from ninep import Client # noqa: E402 -# The caller's PARDES_* is dropped (a session of the user's), these kept: a -# road for every session the run starts (PARDES_TERM_SCREEN: its terminals to -# its clients as screen state, the way back). -KEEP = ('PARDES_TERM_SCREEN',) - - def wait_for(what, check, timeout=10): deadline = time.monotonic() + timeout while True: @@ -108,13 +102,15 @@ class Term: try: if not select.select([self.master], [], [], 0.05)[0]: continue - got = os.read(self.master, 65536) + # Read and kept in one hold of the lock: `last` counts what + # waits on the master under it. + with self.lock: + got = os.read(self.master, 65536) + self.out += got except OSError: return if not got: return - with self.lock: - self.out += got # A request split across two reads is answered too. seen, self.tail = self.tail + got, got[-3:] if b'\x1b[5n' in seen: @@ -133,6 +129,23 @@ class Term: with self.lock: return bytes(self.out) + def last(self): + """Its text once what was written to it is read, for a read after + its writer ended (or wrote its last before an event seen + elsewhere): the reader may not have the last bytes yet (it reads + every 50 ms, later under load). Nothing waiting on the master and + nothing more read for 0.1 s.""" + quiet = None + def done(): + nonlocal quiet + with self.lock: + now = (struct.unpack('i', fcntl.ioctl(self.master, termios.FIONREAD, b'\0\0\0\0'))[0], len(self.out)) + if now[0] or quiet is None or quiet[0] != now: + quiet = (now, time.monotonic()) + return time.monotonic() - quiet[1] >= .1 + wait_for('the terminal\'s last bytes read', done) + return self.text() + def close(self): self.closing = True self.reader.join(timeout=2) @@ -263,7 +276,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 = 29 + WIRE = 30 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout @@ -319,13 +332,13 @@ class Replica: return 'refused', why def ping(self, value): - """One round trip, in ms (the session's units and terminal - messages on the way are passed over).""" + """One round trip, in ms (the session's units on the way are + passed over).""" t = time.monotonic() self.send(0x03, struct.pack('<Q', value)) while True: tag, body = self.read() - if tag not in (0x05, 0x06): + if tag != 0x05: break assert (tag, body) == (0x03, struct.pack('<Q', value)), (tag, body) return (time.monotonic() - t) * 1000 @@ -441,7 +454,7 @@ def clients(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rc-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -529,7 +542,7 @@ def clients(binary): # Detach typed in it: it alone goes, and says so (exit 0). os.write(ta.master, b' sD') wait_for('client A let go', lambda: a.poll() is not None, timeout=10) - assert a.returncode == 0 and b"detached from 'files', which is still running" in ta.text(), ta.text()[-300:] + assert a.returncode == 0 and b"detached from 'files', which is still running" in ta.last(), ta.last()[-300:] # A third client, a shell: its keys wait for the session (a pty # write), its output comes back in units, the same on both sides. nine.write(f'/pane/{pane}/exec', b'Term\n') @@ -583,7 +596,7 @@ def launch(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rl-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -651,7 +664,7 @@ def pair(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rp-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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', PARDES_PAIR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -725,7 +738,7 @@ def pair_rows(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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', PARDES_PAIR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -915,7 +928,7 @@ def attach_upgrading(binary, rounds=6, dump=True): 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_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1002,11 +1015,11 @@ def kept_views(binary): nobody types in: a `new --detach` session at its four views (a client attached, idle; raw replicas), two of them leaving to join again and never coming back; a join at once is refused and told for how long, one - 31 s later, nothing typed in between, is welcomed.""" + a second past that, nothing typed in between, is welcomed.""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rk-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1029,15 +1042,29 @@ def kept_views(binary): for r in rs[:2]: r.send(0x02, b'\x01') r.close() - left = time.monotonic() - said = Replica(sock).hello('kv', build) - assert said[0] == 'refused' and re.search(r'as many views as it takes \(one is kept (\d+) s more for a client joining again\)', said[1]), said - print(f'kept views: {len(rs)} replicas and a client at the cap; two left to join again; a join at once refused: "{said[1]}"') - time.sleep(max(0, left + 31 - time.monotonic())) + + # The goodbyes reach the session on their own connections and the + # next join through the daemon, in no order between them: a join + # judged before the session took them is refused with no view kept + # yet. Dialled again until a refusal says one is. + dials = 0 + + def refused(): + nonlocal dials + dials += 1 + r = Replica(sock) + said = r.hello('kv', build) + r.close() + assert said[0] == 'refused' and 'as many views as it takes' in said[1], said + kept = re.search(r'as many views as it takes \(one is kept (\d+) s more for a client joining again\)', said[1]) + return kept and (said, int(kept.group(1)), time.monotonic()) + said, more, at = wait_for('a join refused, a view kept', refused) + print(f'kept views: {len(rs)} replicas and a client at the cap; two left to join again; a join at once refused: "{said[1]}" ({dials} dials)') + time.sleep(max(0, at + more + 1 - time.monotonic())) said = Replica(sock).hello('kv', build) - assert said[0] == 'welcome', ('a view kept 31 s in an idle session, still kept', said) + assert said[0] == 'welcome', ('a view kept past what its refusal said in an idle session, still kept', more, said) assert a.poll() is None - print('kept views: a join 31 s after, nothing typed in between, took a kept view') + print(f'kept views: a join {more + 1} s after, nothing typed in between, took a kept view') a.terminate() a.wait(timeout=20) assert subprocess.run([binary, 'kill', 'kv'], env=env, capture_output=True, timeout=30).returncode == 0 @@ -1064,7 +1091,7 @@ def pair_upgrade_views(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rv-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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', PARDES_PAIR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -1170,7 +1197,7 @@ def pair_exec_reaps(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rpx-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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', PARDES_PAIR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -1234,7 +1261,7 @@ def far_exec(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rfx-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1300,7 +1327,7 @@ def pair_window_geometry(gui_binary, new_gui): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rgg-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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'), SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_DAEMON='on', TERM='xterm-256color', PARDES_PAIR='1', SDL_VIDEO_DRIVER='offscreen') @@ -1372,7 +1399,7 @@ def manage(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rm-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1476,7 +1503,7 @@ def relink(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1582,7 +1609,7 @@ def answer_late(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ra-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1700,7 +1727,7 @@ def pdf_window(binary, gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='pdfw-', dir=os.environ.get('TMPDIR') or scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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') env.pop('XDG_DATA_HOME', None) @@ -1766,7 +1793,7 @@ def window_clients(binary, gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='wc-', dir=os.environ.get('TMPDIR') or scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -1988,7 +2015,7 @@ def far(binary): scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rf-', dir=scratch)) cache = root / 'cache' - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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', PARDES_REPLICA_FAR='1') @@ -2147,15 +2174,18 @@ def far(binary): 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.""" + 200 ms each way, 20 KB/s) while the session's shell runs `yes`. Its + terminal is the pty's bytes in the session's units, so the flood queues + for it: it falls behind, past replica.behind_max_ms its link is let go + (`Link.lags`), and it joins again from a dump, saying so on its notice + line ("joined again: N s behind") until a key. Once `yes` ends it agrees + with the session, and its keys after go in. The shape is asserted, not + the times: a link ended before its last (a line of + PARDES_REPLICA_STATS a link), the notice, the agreement.""" 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_') or k in KEEP) and 'PAGER' not in k} + 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') @@ -2184,16 +2214,21 @@ def far_flood(binary): started.append(relay.pid) wait_for('the relay', (root / 'relay.sock').exists) check = root / 'f.check' + stats = root / 'f.stats' 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))) + dict(env, PARDES_REPLICA_FAR='1', PARDES_REPLICA_CHECK=str(check), PARDES_REPLICA_STATS=str(stats))) 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) + # Queued behind the flood, let go for its lag, joined again from a + # dump: a link of its ended (its stats line), and its notice says why. + assert joins(stats), ('no link of the far client ended under the flood', checks(stats)) + wait_for('the far client\'s notice of its join again', lambda: b'joined again: ' in t.text() and b' s behind' in t.text(), timeout=30) 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)) @@ -2201,14 +2236,33 @@ def far_flood(binary): # 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') + print(f'daemon: a far client across 20 KB/s and 200 ms each way under `yes` was let go for its lag and ' + f'joined again ({len(joins(stats))} links), agreed once it ended ({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) + except BaseException: + # Its evidence kept, the root going: the far client's checks and + # stats, its terminal, and where each process's threads wait. + kept = Path(tempfile.mkdtemp(prefix='fl-kept-', dir=scratch)) + for f in ('f.check', 'f.stats'): + if (root / f).exists(): + shutil.copy(root / f, kept) + for i, term in enumerate(terms): + (kept / f'term-{i}.out').write_bytes(term.text()) + with open(kept / 'threads', 'w') as out: + for pid in started: + out.write(f'{pid} {cmdline(pid)[:3]} alive={alive(pid)}\n') + for task in sorted(Path(f'/proc/{pid}/task').glob('*')) if procfs and alive(pid) else []: + try: + out.write(f' {task.name} {(task / "comm").read_text().strip()} {(task / "wchan").read_text()}\n') + except OSError: + pass + print(f'far flood: kept {kept}', file=sys.stderr) + raise finally: for term in terms: term.close() @@ -2230,7 +2284,7 @@ def by_hash(binary): 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_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -2316,7 +2370,7 @@ def games(binary, libs, secs=10): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rg-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2427,7 +2481,7 @@ def far_find(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_REPLICA_FAR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2494,7 +2548,7 @@ def restore_client(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2621,14 +2675,14 @@ def cpu_ticks(pid): def kitty_image(binary, secs=5): - """A plain attach (screen state) watching a terminal in which a program + """A plain attach watching a terminal in which a program shows a kitty image (the corpus's scene 10's: 8x8 RGB, 10x4 cells): it agrees with its session and does not join again (it joined again ~3.3 times a second: the tag said ` petscii:on` on the session's side only).""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ri-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -2689,7 +2743,7 @@ def main(binary, cycles): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rt-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -2859,7 +2913,7 @@ def main(binary, cycles): os.kill(stub, signal.SIGKILL) wait_for('the stub gone', lambda: not alive(stub)) wait_for('the session detached from its killed stub', lambda: sized(client)) - assert b'\x1b[?1049l' in term.text()[drawn:], 'the terminal is put back' + assert b'\x1b[?1049l' in term.last()[drawn:], 'the terminal is put back' assert alive(session) shell.kill() shell.wait(timeout=10) @@ -2887,7 +2941,7 @@ def main(binary, cycles): # the daemon go. exit_session(client, pane) assert stub.wait(timeout=10) == 0, stub.returncode - assert b'let this client go' not in term.text(), term.text()[-300:] + assert b'let this client go' not in term.last(), term.last()[-300:] client.socket.close() term.close() wait_for('the adopted shell hung up', lambda: not alive(shell_pid)) @@ -2923,7 +2977,7 @@ def gui(binary, cycles): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rtg-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} (root / 'caps').mkdir() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_TEST='1', PARDES_TEST_CAPTURE_DIR=str(root / 'caps'), @@ -3018,7 +3072,7 @@ def gui_pair(gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rgp-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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'), SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_DAEMON='on', TERM='xterm-256color', PARDES_PAIR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -3189,7 +3243,7 @@ def upgrades(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rtu-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -3271,7 +3325,8 @@ def upgrades(old, new): replica.close() stale.wait(timeout=30) # (Across a change of the replica protocol, it says that instead.) - assert b'upgrade this client too' in term3.text() or b'run the same pardes at both ends' in term3.text(), term3.text()[-400:] + said = term3.last() + assert b'upgrade this client too' in said or b'run the same pardes at both ends' in said, said[-400:] term3.close() print('upgrade: a replica client of the old build was let go, dialled again and was told to upgrade too') # The old image's prompt files swept, the new one's made. @@ -3498,7 +3553,7 @@ def upgrade_clients(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ruc-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + 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) @@ -3600,7 +3655,7 @@ def gui_upgrades(old, new): another build.""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' root = Path(tempfile.mkdtemp(prefix='rtgu-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if (not k.startswith('PARDES_') or k in KEEP) and 'PAGER' not in k} + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} display = Path(os.environ.get('WAYLAND_DISPLAY', 'wayland-0')) if not display.is_absolute(): display = Path(os.environ.get('XDG_RUNTIME_DIR', f'/run/user/{os.getuid()}')) / display |
