diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 394 | ||||
| -rw-r--r-- | test/panes.zig | 84 |
2 files changed, 478 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py index adfbc52a..97b0de76 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -48,6 +48,18 @@ private HOME and runtime directory: python3 -B test/daemon.py --window-clients <pardes> <pardes-gui> window replica clients (hidden, offscreen) of a terminal's session, at 0/30/80/207 ms, and a window's session serving replicas + python3 -B test/daemon.py --client-motion <pardes> <pardes-gui> + a run of pointer motions over a client window is a few inputs, not + one each (also run by --window-clients) + python3 -B test/daemon.py --client-resize-real <pardes> <pardes-gui> + a client window showing a PDF resized 30 times in a second by the + real compositor (driftwm), the caller's display: no SDL assertion, + the last size taken, an input a size at most + python3 -B test/daemon.py --client-idle <pardes> <pardes-gui> + a window's session (the test surface, and offscreen with no test + mode) and a terminal's, each with a PDF and a terminal client, + nobody typing: no more steps than the text alone (pdf.so in both + prefixes) """ import fcntl import json @@ -2145,6 +2157,381 @@ def window_clients(binary, gui_binary): shutil.rmtree(root, ignore_errors=True) +def client_motion(binary, gui_binary): + """A run of pointer motions is one move to its last position (gui.zig + Input.moved), over a client window and over the session's own window + with a client attached: not an input each, which the session steps one + by one and sends every client as a unit each, every one of them + replayed and drawn again (the user's "resizing feels very slow with + several clients", 2026-11-24: a 1000 Hz mouse is a thousand inputs a + second). 300 motions written at once, 30 bytes each: the window takes + them a read of its test feed (1024 bytes) a pass, so at most ten + passes, each one input; with the five a client makes anyway (what it + is, its size, its focus, two keys) at most 15, asserted at most 20. + Three roads: the feed's own dispatch (`motion`) and SDL's queue + (`pointer`: the same motion pushed as a mouse's comes) over a window + client of a terminal's session, the inputs it sent the session (its + PARDES_REPLICA_STATS); and SDL's queue over a window's session with a + terminal client watching, a drag, the frames the window drew (its + status: on main each motion was its own wait, `split`, a frame each).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='cm-', dir=os.environ.get('TMPDIR') or scratch)) + env = base_env() + 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) + (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, windows = [], [], [] + 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') + tt = Term(24, 80) + terms.append(tt) + t = tt.spawn([binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_STATS=str(root / 't.stats'))) + started.append(t.pid) + wait_for('the terminal client\'s first frame', lambda: b'line 3 of the notes' in tt.text(), timeout=30) + motions = 300 + + def burst(win, kind, button=0): + win.p.stdin.write(b''.join(f'\x1b]777;mouse;{kind};{button};{200 + 3 * i};{300 + i % 40}\x07'.encode() for i in range(motions))) + win.p.stdin.flush() + + def said(path, word): + line = checks(path)[-1].split() + return int(line[line.index(word) + 1]) + + sent = {} + for kind in ('motion', 'pointer'): + stats = root / f'w-{kind}.stats' + w = Window(root, f'w-{kind}', [gui_binary, f'--attach={sock}:files'], dict(env, PARDES_REPLICA_STATS=str(stats))) + windows.append(w) + started.append(w.pid) + w.keys(b'jj') + wait_for('the window\'s keys in the session', lambda: b'line' in nine.read(f'/pane/{pane}/body'), timeout=30) + time.sleep(2) + burst(w, kind) + time.sleep(3) + assert w.close() == 0, w.said()[-800:] + sent[kind] = said(stats, 'inputs') + t.send_signal(signal.SIGHUP) + t.wait(timeout=10) + tt_units = said(root / 't.stats', 'units') if checks(root / 't.stats') else None + print(f'daemon: {motions} motions over a client window: it sent the session {sent["motion"]} inputs by the feed, ' + f'{sent["pointer"]} by SDL\'s queue; the terminal client took {tt_units} units') + for kind, n in sent.items(): + assert n <= 20, (f'{motions} pointer motions ({kind}) over a client window were {n} inputs to its session, ' + 'each a unit for every client: not one a pass') + exit_session(nine, pane) + sess.wait(timeout=60) + nine.socket.close() + # The session's own window, a terminal client watching: SDL's queue. + win = Window(root, 'win', [gui_binary, '--9p=win', str(notes)], dict(env, PARDES_DAEMON='on')) + windows.append(win) + started.append(win.pid) + wait_for('the window session\'s 9P socket', (root / 'pardes-9p-win.sock').exists, timeout=30) + wait_for('the replica socket', sock.exists) + nine = Client(root / 'pardes-9p-win.sock') + pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + tb = Term(24, 80) + terms.append(tb) + b = tb.spawn([binary, f'--attach={sock}:win'], dict(env, PARDES_REPLICA_STATS=str(root / 'b.stats'))) + started.append(b.pid) + wait_for('the terminal client\'s first frame', lambda: b'line 3 of the notes' in tb.text(), timeout=30) + time.sleep(2) + + def frames(): + return int((root / 'win' / 'status').read_text().split()[1]) + + # A drag selecting: each motion moves what the window shows. + win.mouse('down', 1, 200, 300) + time.sleep(1) + before = frames() + burst(win, 'pointer', 1) + time.sleep(3) + drawn = frames() - before + win.mouse('up', 1, 1097, 339) + time.sleep(1) + b.send_signal(signal.SIGHUP) + b.wait(timeout=10) + print(f'daemon: {motions} motions of a drag over the session\'s own window, a terminal client watching: ' + f'the window drew {drawn} frames; the client {said(root / "b.stats", "draws")} in all') + assert drawn <= 20, (f'{motions} pointer motions over the session\'s window were {drawn} frames of it with a client ' + 'attached: each motion its own wait (split), a step and a unit each, not one a pass') + exit_session(nine, pane) + assert win.close() == 0, win.said()[-800:] + nine.socket.close() + finally: + for tm in terms: + tm.close() + for w in windows: + if w.p.poll() is None: + w.p.kill() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + +def idle_session(binary, gui_binary, surface, pdf, secs): + """One session (`surface`: a window's on the test surface; a window's + offscreen with no test mode, `loop`: the loop a real window runs, asleep + until an event or its deadline; or a terminal's with its own terminal), + a text and, with `pdf`, a PDF, one terminal client attached, nobody + typing for `secs`: the session's boundaries and the units the client + took over its whole life, and the CPU each spent in the idle seconds + (ticks of 10 ms).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='ci-', dir=os.environ.get('TMPDIR') or scratch)) + env = base_env() + 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) + (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(60))) + stats = root / 'session.stats' + started, terms, windows = [], [], [] + try: + if surface == 'window': + win = Window(root, 'win', [gui_binary, '--9p=idle', str(notes)], dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats))) + windows.append(win) + started.append(win.pid) + elif surface == 'loop': + started.append(subprocess.Popen([gui_binary, '--9p=idle', str(notes)], cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, start_new_session=True, + env=dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats), SDL_VIDEO_DRIVER='offscreen')).pid) + else: + ts = Term(30, 100) + terms.append(ts) + started.append(ts.spawn([binary, '--tty', '--9p=idle', str(notes)], dict(env, PARDES_REPLICA_STATS=str(stats))).pid) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-idle.sock').exists, timeout=30) + nine = Client(root / 'pardes-9p-idle.sock') + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + started.append(session) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists, timeout=30) + pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + if pdf: + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + nine.write(f'/pane/{pane}/look', f'{doc}\n'.encode()) + wait_for('the PDF shown', lambda: any(row.split()[1] == b'pdf' for row in nine.read('/index').splitlines()), timeout=30) + tc = Term(24, 80) + terms.append(tc) + c = tc.spawn([binary, f'--attach={sock}:idle'], dict(env, PARDES_REPLICA_STATS=str(root / 'c.stats'))) + started.append(c.pid) + wait_for('the client\'s first frame', lambda: b'notes' in tc.text(), timeout=30) + # Its join and the frames after it over. + time.sleep(1.5) + cpu = (cpu_ticks(session), cpu_ticks(c.pid)) + time.sleep(secs) + cpu = (cpu_ticks(session) - cpu[0], cpu_ticks(c.pid) - cpu[1]) + c.send_signal(signal.SIGHUP) + c.wait(timeout=10) + line = checks(root / 'c.stats')[-1].split() + units = int(line[line.index('units') + 1]) + exit_session(nine, pane) + wait_for('the session ended', lambda: not alive(session), timeout=60) + nine.socket.close() + return int(session_stats(stats)[0]['boundaries']), units, cpu + finally: + for t in terms: + t.close() + for w in windows: + if w.p.poll() is None: + w.p.kill() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + +def client_idle(binary, gui_binary, secs=5): + """An idle session sends nothing (2026-11-24: a PDF in a window's session + with a client attached stepped the session ~700 times a second, nobody + typing, each step a unit every client replayed): a session showing a + text and a PDF, one terminal client, nobody typing for `secs`, takes at + most the steps the same session with the text alone takes, plus the + PDF's own opening (its page drawn, its views told: `opening`). On the + test surface the window's loop polls its feed every 16 ms, a step and a + unit each (the text alone's count is that rate); a window's own loop + (`loop`: offscreen, no test mode) and a terminal's session step for + nothing. The PDF's addon (`<prefix>/lib/pardes/addons/pdf.so`, `zig + build addons`) beside each binary.""" + for b in (binary, gui_binary): + lib = Path(b).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + assert lib.exists(), f'no {lib}: the PDF is this test\'s subject (zig build install addons into that prefix)' + opening = 40 + flooded = [] + for surface in ('window', 'loop', 'tty'): + text = idle_session(binary, gui_binary, surface, False, secs) + shown = idle_session(binary, gui_binary, surface, True, secs) + print(f'daemon: a {surface}\'s session idle {secs} s, a terminal client attached: ' + f'text alone {text[0]} boundaries, the client {text[1]} units, CPU {text[2][0] * 10}/{text[2][1] * 10} ms; ' + f'with a PDF {shown[0]} boundaries, {shown[1]} units, CPU {shown[2][0] * 10}/{shown[2][1] * 10} ms (session/client)') + if shown[0] > text[0] + opening or shown[1] > text[1] + opening: + flooded.append(f'{surface}: {shown[0]} boundaries and {shown[1]} units against the text alone\'s {text[0]} and {text[1]}') + assert not flooded, (f'a session showing a PDF, a client attached, nobody typing for {secs} s, steps with nothing to do, ' + f'a unit every client replays: {"; ".join(flooded)}') + + +def client_resize_real(binary, gui_binary): + """A client window resized by a real compositor (driftwm's `msg resize`, + the configures a drag sends: 30 sizes in a second) while it shows a PDF: + no SDL assertion (on main every frame drawn larger than the target it + is drawn into placed the page's scissor past it: `SDL_SetGPUScissor`'s + release assertion, whose dialog blocks the window's thread: the window + frozen at its old size, cut, and nothing opened after shows in it), it + takes the last size, it posts a size a configure at most and is rolled + back as often at most (on main the session's own window sized the + client's view to its own size, the client posted its own again, on and + on: 425 to 1308 inputs, 228 rollbacks, its frames drawn at the session + window's size, cut). Real windows: the + caller's display and runtime directory reach the compositor; the + session's runtime directory is the test's own; skipped without driftwm.""" + real_runtime = os.environ.get('XDG_RUNTIME_DIR', '') + wayland = os.environ.get('WAYLAND_DISPLAY') or 'wayland-1' + display = wayland if wayland.startswith('/') else os.path.join(real_runtime, wayland) + lib = Path(binary).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + if not shutil.which('driftwm') or not os.path.exists(display) or not lib.exists(): + print('daemon: client resize on a real compositor: skipped (no driftwm, display or pdf.so)') + return + drift_env = dict(os.environ, XDG_RUNTIME_DIR=real_runtime, WAYLAND_DISPLAY=wayland) + + def drift(*args): + out = subprocess.run(['driftwm', 'msg', '--json', *map(str, args)], env=drift_env, capture_output=True, text=True, timeout=10) + return json.loads(out.stdout) if out.stdout.strip() else {} + + def window_of(pid): + state = drift('state')['Ok']['State'] + return next((w for w in state['windows'] if w.get('pid') == pid), None) + + def away(pid, x, y): + """The window moved far from the desktop user's view, and kept + there: driftwm places a window again when it maps, after a move made + before (it came back beside the user's view, 2026-11-24).""" + wid = window_of(pid)['id'] + still = 0 + for _ in range(300): + if window_of(pid)['position'] != [x, y]: + drift('move', '--id', wid, x, y) + still = 0 + else: + still += 1 + if still == 40: + return wid + time.sleep(0.05) + raise AssertionError(('a test window would not stay away from the desktop user\'s view', window_of(pid))) + + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='cr-', dir=os.environ.get('TMPDIR') or scratch)) + env = base_env() + 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', SDL_AUDIODRIVER='dummy') + env.pop('XDG_DATA_HOME', None) + (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))) + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + started = [] + try: + state = drift('state')['Ok']['State'] + focused = next((w['id'] for w in state['windows'] if w.get('is_focused')), None) + # The session a window of its own, as a desktop's is, its daemon on; + # a terminal with output in it beside the PDF. + sess = subprocess.Popen([gui_binary, '--9p=files', str(notes), '--geometry=1120x760'], + env=dict(env, PARDES_DAEMON='on', WAYLAND_DISPLAY=display, SDL_VIDEO_DRIVER='wayland', SDL_ASSERT='ignore'), + cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(root / 's.err', 'w'), + start_new_session=True) + started.append(sess.pid) + wait_for('the session\'s window', lambda: (window_of(sess.pid) or {}).get('id'), timeout=30) + away(sess.pid, 59400, -18000) + if focused is not None: + drift('focus', '--id', focused) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists, timeout=30) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-files.sock').exists, timeout=30) + 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')) + nine.write(f'/pane/{shell}/pty/data', b'seq 1 400\r') + nine.write(f'/pane/{pane}/look', f'{doc}\n'.encode()) + wait_for('the PDF pane', lambda: any(row.split()[1] == b'pdf' for row in nine.read('/index').splitlines())) + err = root / 'w.err' + stats = root / 'w.stats' + # SDL's assertion counted on stderr, never its dialog on the desktop. + w = subprocess.Popen([gui_binary, f'--attach={sock}:files', '--geometry=900x600'], + env=dict(env, WAYLAND_DISPLAY=display, SDL_VIDEO_DRIVER='wayland', SDL_ASSERT='ignore', + PARDES_REPLICA_STATS=str(stats), SDL_EVENT_LOGGING='2'), + cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(err, 'w'), start_new_session=True) + started.append(w.pid) + wait_for('the client\'s window', lambda: (window_of(w.pid) or {}).get('id'), timeout=30) + # Far from where the desktop's user looks, the focus given back. + wid = away(w.pid, 62000, -18000) + if focused is not None: + drift('focus', '--id', focused) + time.sleep(3) + steps = 30 + t0 = time.monotonic() + for i in range(steps): + time.sleep(max(0, t0 + i / 30 - time.monotonic())) + last = (900 + 9 * (i + 1), 600 + 5 * (i + 1)) + drift('resize', '--id', wid, *last) + time.sleep(3) + size = window_of(w.pid)['size'] + said = err.read_text(errors='replace') + w.send_signal(signal.SIGTERM) + w.wait(timeout=15) + line = checks(stats)[-1].split() if checks(stats) else [] + sent = int(line[line.index('inputs') + 1]) if 'inputs' in line else -1 + # SDL's default handler's words, and pardes's own (gui.zig sdlAssertion). + asserted = said.count('Assertion failure') + said.count('SDL assertion: ') + # A pointer that crossed the window (one sliding under it as it was + # moved away) is motion's, --client-motion's: not counted here. + motions = said.count('SDL_EVENT_MOUSE_MOTION') + sent -= motions + # Its own inputs rolled back by the session's units between them. + rollbacks = int(line[line.index('foreign') + 1]) if 'foreign' in line else -1 + print(f'daemon: a client window resized {steps} times in a second by the compositor: {asserted} SDL assertions, ' + f'its size {size} (asked {list(last)}), {sent} inputs besides {motions} pointer motions, {rollbacks} rollbacks') + assert asserted == 0, ('a client window drew past its target while resized', said[-600:]) + assert abs(size[0] - last[0]) <= 2 and abs(size[1] - last[1]) <= 40, ('the client window did not take the last size', size, last) + # A size a configure at most (the window's own, compared with what it + # posted last: none after the last). + assert sent <= steps, ('a client window resized posted its size again and again', sent) + assert 0 <= rollbacks <= steps + motions, ('a client window resized was rolled back again and again', rollbacks) + exit_session(nine, pane) + sess.wait(timeout=60) + nine.socket.close() + finally: + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + def joins(path): """A replica client's joins (PARDES_REPLICA_STATS, a line a link): how many blobs each listed, how many it held already from the core it left @@ -4212,6 +4599,13 @@ if __name__ == '__main__': elif sys.argv[1:2] == ['--window-clients']: window_clients(sys.argv[2], sys.argv[3]) pdf_window(sys.argv[2], sys.argv[3]) + client_motion(sys.argv[2], sys.argv[3]) + elif sys.argv[1:2] == ['--client-motion']: + client_motion(sys.argv[2], sys.argv[3]) + elif sys.argv[1:2] == ['--client-resize-real']: + client_resize_real(sys.argv[2], sys.argv[3]) + elif sys.argv[1:2] == ['--client-idle']: + client_idle(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--ping']: ping(sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5]) if len(sys.argv) > 5 else 50) elif sys.argv[1:2] == ['--pair-gui']: diff --git a/test/panes.zig b/test/panes.zig index eea4b36d..ba3466fb 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -4049,6 +4049,90 @@ const PdfAddon = struct { } } + /// A session's loop with nobody typing: each wait runs out at its + /// deadline, and the clock read after it is the shells' (Peers.heldNow, + /// as gui.zig `guiNow` and tui.zig `clockNow` read it: a wait that took + /// nothing else, `only_mail`). + const Idle = struct { + now: u64 = std.time.ns_per_s, + waited: bool = false, + core: ?*Pardes = null, + peers: pardes.replica.Peers = .{ .gpa = std.testing.allocator, .io = std.testing.io }, + + const vtable: pardes.Host.VTable = .{ + .wait_input = wait, + .now = clock, + .watched = host_vtable.watched, + .job = host_vtable.job, + }; + + fn wait(ctx: ?*anyopaque, timeout_ms: u32) void { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + h.now += @as(u64, timeout_ms) * std.time.ns_per_ms; + h.waited = true; + } + + fn clock(ctx: ?*anyopaque) u64 { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + if (!h.waited) return h.now; + h.waited = false; + return h.peers.heldNow(h.core orelse return h.now, true) orelse h.now; + } + }; + + test "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" { + // 2026-11-24: a window's session showing a PDF, a client attached, + // stepped ~700 times a second with nobody typing: the client's view + // owed to the kind (Kind.wake: now), a wait of a millisecond that + // ran out, and the clock after it held as if a client had posted + // (gui.zig guiNow: its wait's `mail_only` is cleared by an event, + // and one that ran out had none), so no step met the deadline. + if (!addons.has_pdf) return error.SkipZigTest; + const R = pardes.replica; + var idle: Idle = .{}; + defer idle.peers.deinit(); + const a = try R.Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .ctx = &idle, .vtable = &Idle.vtable }); + defer a.deinit(); + idle.core = a.core; + const Land = struct { + a: *R.Authority, + fn step(l: @This(), ev: pardes.Event) !void { + _ = try l.a.local(ev); + } + }; + const id = try opened(a, Land{ .a = a }); + const slot = a.core.panes[id].?.addon.?; + // A client attached (units go to it), its view sized by its input: + // a client's step tells no kind (17.2), so its view is owed. + idle.peers.recording = true; + const k = (try a.openView(2)).view; + const was = pardes.tape.on; + pardes.tape.on = &a.t; + const bytes = try pardes.dump.byteDump(a.core); + pardes.tape.resync(&a.t); + pardes.tape.on = was; + defer a.core.gpa.free(bytes); + const win = try R.Replica.initDump(std.testing.allocator, 2, k, bytes, .{ .cols = 80, .rows = 24 }); + defer win.deinit(); + _ = try a.take(try win.input(.{ .resize = .{ .cols = 80, .rows = 24 } })); + try std.testing.expect(pardes.Kind.viewOwed(a.core, slot, id)); + // ONE pump, nobody typing: its wait runs out at the wake, the step + // it asked for tells the view, and nothing is owed after. + a.pump(); + try std.testing.expect(!pardes.Kind.viewOwed(a.core, slot, id)); + try std.testing.expect((pardes.Kind.wake(a.core) orelse std.math.maxInt(u64)) > a.core.clock.now_ns); + // A client's post waiting (its input, its join): the pump before + // the boundary takes it reads the clock as it stands. + const at = a.core.clock.now_ns; + idle.now += std.time.ns_per_s; + idle.peers.mail.store(true, .release); + a.pump(); + try std.testing.expectEqual(at, a.core.clock.now_ns); + idle.peers.mail.store(false, .release); + a.pump(); + try std.testing.expectEqual(idle.now, a.core.clock.now_ns); + } + test "a PDF pane whose file changes on disk opens again from it at its page, its fit kept" { if (!addons.has_pdf) return error.SkipZigTest; const gpa = std.testing.allocator; |
