summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 14:43:18 -0300
committerGabriel Schneider <[email protected]>2026-11-24 15:22:25 -0300
commit4ae132650106242a5130aad5230c4f429bf02b29 (patch)
tree0bbb733990ac65a00f15f786741015726a9ee4d0 /test/panes.zig
parent6fdf2bf2b1a90714ba998fa959db33089abb9f56 (diff)
downloadpardes-4ae132650106242a5130aad5230c4f429bf02b29.tar.gz
pardes-4ae132650106242a5130aad5230c4f429bf02b29.zip
replica, gui, tui: the clock a session's pump reads after its wait is held only while a client's post waits for it (Peers.heldNow, which both shells' clocks call), so a wait that ran out always reads the clock and its step meets the deadline it waited for: a window's session showing a PDF with a client attached stepped ~700 times a second with nobody typing, each step a unit every client replayed (the multi-client line's "a PDF in a window's session floods every client"); RUN (an instrumented Debug build, the window's loop offscreen with no test mode, a terminal client; .scratch reorg/pardes-idle-flood/runs/probe): the client's view of the PDF (pane 1, view 1: 78x9, 8x16, glyphs) owed to the kind from its join on (Kind.wake: now, so nextWake a frame on), and 2247 of 2268 pumps 'mail_only true, mail false, wait ran out', the clock read after each the one held at the join (1.302 s while the real one ran to 2.93 s), so advance never reached the deadline, the view was never told, and the next wait was 1 ms: for ever; THE CAUSE: dev/gui/gui.zig guiNow held the clock after any wait whose `mail_only` was still set, and waitInput sets it at a wait's start and clears it only for an event that is not a replica's wake or a queue message: a wait that ran out (SDL_WaitEventTimeout false, waitDetached's too) took no post and still held the clock; a terminal's session never did (its wait ends in a .wake event, tui.zig apply clears it); THE FIX: Peers.heldNow (core/replica.zig): held only when the wait took nothing else (the shell's `mail_only`), a client is attached (`recording`), a post waits to be taken (`mail`, set by post, cleared at the boundary) and the clock has started; gui.zig guiNow and tui.zig clockNow call it (their own copies of the rule gone), so no shell's wait can hold the clock without a post; TEST FIRST: test/panes.zig "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" (on the base's rule, the same function without `mail`: fails at panes.zig:4120, the view still owed after the pump); test/daemon.py --client-idle on this build: the window's loop 7 boundaries and 8 units with a PDF against the text alone's 5 and 6 (4871 and 4872 on the base), the test surface 223 against 207 (388 against 206), the terminal's 8 against 5; a user hit it: every window's session with a client attached and a deadline owed (a PDF's view, a message's linger, a Life's tick, a look's hover) stepped and sent a unit a millisecond until someone typed in the window
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/panes.zig b/test/panes.zig
index bd39beba..28a3b256 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -4047,6 +4047,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;