diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pardes.zig | 10 | ||||
| -rw-r--r-- | src/replica.zig | 55 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 36ce6bdb..5b37342e 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -5669,6 +5669,11 @@ pub const Pardes = struct { pub fn openView(p: *Pardes) ?u8 { const taped = tape.enter(p, .open_view); defer tape.leave(p, taped); + // What was queued since the last pump (a leaving client's view + // closed, a 9P request's step) done first, as every client of the + // tape does it here: a join dumps the session next, and a core + // loaded from a dump has no queue (Replica.initDump). + p.settle(); p.needs_frame = true; return views.open(p); } @@ -5680,6 +5685,11 @@ pub const Pardes = struct { defer tape.leave(p, taped); views.close(p, k); p.sync(); + // What its sync queued (a terminal it sized, sized again) done here, + // in its own unit on every side: the session's next pump is another + // unit, and a replica takes a copy only of a core with nothing + // queued (rollback.Copy.take). + p.settle(); } /// Into view `k`, before the input its client sent. diff --git a/src/replica.zig b/src/replica.zig index 8b1d84f4..22de375f 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -3439,3 +3439,58 @@ test "a replica's Del of a file its session's Recent knows asks the host what th try agrees(a, r); } +/// A host with ptys whose pump polls for a frame, as a client's does. +const PtyHost = struct { + fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {} + fn poll(_: ?*anyopaque) void {} + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll }; + fn host() pardes.Host { + return .{ .vtable = &vtable }; + } +}; + +fn inputOf(buf: []u8, client: u16, seq: u32, ev: pardes.Event) ![]const u8 { + const n = (try wire.encodeClient(buf[head_len..], .{ .event = ev })).len; + header(buf, client, seq); + return buf[0 .. head_len + n]; +} + +test "a client leaves, and one joins: what the leave queued (a terminal's resize) is done in its unit, on every side, before the join's dump" { + if (comptime !terminal.enabled) return error.SkipZigTest; + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, PtyHost.host(), true); + defer a.deinit(); + const first = try gpa.dupe(u8, try a.unit(0, 0)); + defer gpa.free(first); + const old = try Replica.init(gpa, 1, first, true); + defer old.deinit(); + // A second client, bigger, types into the terminal: it sizes it. + const opened = try a.openView(2); + old.confirm(opened.unit); + var buf: [256]u8 = undefined; + old.confirm(try a.take(try inputOf(&buf, 2, 1, .{ .resize = .{ .cols = 120, .rows = 40 } }))); + old.confirm(try a.take(try inputOf(&buf, 2, 2, .{ .key = .{ .cp = 'x', .text = "x" } }))); + // It leaves: the terminal is the first view's size again, its pty's + // resize queued for the next pump; and a client joins at that boundary. + var was = Stepping.begin(&a.t, null); + a.core.closeView(opened.view); + was.end(); + old.confirm(try a.unit(0, 100)); + // The client left idle takes its copy ahead (Replica.ready): of a core + // with nothing queued. + old.ready(); + was = Stepping.begin(&a.t, null); + const k = a.core.openView() orelse return error.NoView; + was.end(); + old.confirm(try a.unit(0, 101)); + const joiner = try joinedNow(a, 3, k); + defer joiner.deinit(); + try std.testing.expectEqual(digestOf(a), joiner.digest()); + // The next pump's unit, every client's. + const u = try gpa.dupe(u8, try a.local(.tick)); + defer gpa.free(u); + old.confirm(u); + joiner.confirm(u); + try agrees(a, old); + try agrees(a, joiner); +} |
