summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/replica.zig63
1 files changed, 19 insertions, 44 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 633080e7..8bc27256 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -3223,19 +3223,6 @@ test "another client's input first: a replica rolls back, replays it and applies
try std.testing.expectEqual(@as(u32, 4), r2.stats.fast);
}
-fn screensTo(a: *Authority, screens: *Screens, peer: u16, r: *Replica) !void {
- const gpa = std.testing.allocator;
- var msgs: std.ArrayListUnmanaged([]u8) = .empty;
- defer {
- for (msgs.items) |m| gpa.free(m);
- msgs.deinit(gpa);
- }
- try screens.flush(a.core, peer, &msgs);
- for (msgs.items) |m| if (r.screen(m)) |reply| {
- _ = try screens.take(a.core, peer, reply);
- };
-}
-
test "a delta applied under a speculation outlives its rollback: the terminal stays the authority's newest" {
if (comptime !terminal.enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;
@@ -3255,7 +3242,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
if (slot) |pane| if (pane.file != null) break id;
} else return error.NoTextPane;
r.confirm(try a.local(.{ .focus = true }));
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
var sent: std.ArrayListUnmanaged([]u8) = .empty;
defer {
for (sent.items) |m| gpa.free(m);
@@ -3272,7 +3259,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
r.confirm((try a.pending()).?);
r.settle();
try std.testing.expect(r.copy.held);
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
// The rows the core keeps, read once under the copy.
_ = try terminal.shellRows(r.core(), r.core().panes[shell].?);
}
@@ -3282,7 +3269,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
gpa.free(m);
}
sent.clearRetainingCapacity();
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
// Drawn (its rows read, between steps), then typed into: the copy keeps
// those rows. The shell prints, its delta lands under the copy, and then
// another's unit puts the copy back: the rows it kept are of an older
@@ -3293,7 +3280,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } });
r.confirm((try a.pending()).?);
r.settle();
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
r.confirm(try a.local(.{ .focus = true }));
r.settle();
const n = a.core.panes[shell].?.rows;
@@ -3304,7 +3291,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st
r.confirm(try a.take(m));
r.settle();
}
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why});
try std.testing.expect(r.diverged == null and r.quiet());
try std.testing.expectEqual(digestOf(a), r.digest());
@@ -3397,24 +3384,6 @@ test "a view that sized a terminal closing leaves nothing queued: the others' re
try std.testing.expectEqual(digestOf(a), r1.digest());
}
-/// What the session sends a peer around a step's unit (Peers.input): the
-/// rows the step read that the peer lacks, then the sizes the step gave
-/// terminals (`terminal.resizeDeferred`), then the unit.
-fn fillTo(a: *Authority, screens: *Screens, peer: u16, r: *Replica) !void {
- const gpa = std.testing.allocator;
- var msgs: std.ArrayListUnmanaged([]u8) = .empty;
- defer {
- for (msgs.items) |m| gpa.free(m);
- msgs.deinit(gpa);
- }
- try screens.fill(a.core, peer, &msgs);
- for (msgs.items) |m| if (r.screen(m)) |reply| {
- _ = try screens.take(a.core, peer, reply);
- };
- screens.filled(a.core);
- terminal.resizeDeferred(a.core);
-}
-
test "a terminal sized again by a client's key: the step reads the grid it had, on both sides" {
if (comptime !terminal.enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;
@@ -3444,7 +3413,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
const opened = try a.openView(1);
r.view = opened.view;
r.confirm(opened.unit);
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
var sent: std.ArrayListUnmanaged([]u8) = .empty;
defer {
for (sent.items) |m| gpa.free(m);
@@ -3452,10 +3421,11 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
}
const Step = struct {
fn take(au: *Authority, sc: *Screens, pe: u16, rr: *Replica, msg: []const u8) !void {
- try screensTo(au, sc, pe, rr);
+ try deliver(au, sc, pe, rr, .flush);
const u = try std.testing.allocator.dupe(u8, try au.take(msg));
defer std.testing.allocator.free(u);
- try fillTo(au, sc, pe, rr);
+ try deliver(au, sc, pe, rr, .fill);
+ terminal.resizeDeferred(au.core);
rr.confirm(u);
rr.settle();
}
@@ -3469,7 +3439,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
// The session's view types into it, which sizes it back (the client's
// copy of its history all holes again, a new numbering); then the
// client's key that reads all of it, and sizes it again.
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
{
const was = Stepping.begin(&a.t, null);
a.core.toView(0);
@@ -3480,19 +3450,24 @@ test "a terminal sized again by a client's key: the step reads the grid it had,
a.seq += 1;
const back = try gpa.dupe(u8, try a.unit(0, a.seq));
defer gpa.free(back);
- try fillTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .fill);
+ terminal.resizeDeferred(a.core);
r.confirm(back);
r.settle();
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
try key(r, 'w', &sent);
try key(r, 'w', &sent);
for (sent.items) |m| try Step.take(a, &screens, peer, r, m);
- try screensTo(a, &screens, peer, r);
+ try deliver(a, &screens, peer, r, .flush);
if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why});
try std.testing.expect(r.diverged == null and r.quiet());
try std.testing.expectEqual(digestOf(a), r.digest());
}
+/// What the session sends a peer: its terminals' changes (`.flush`), or,
+/// around a step's unit (Peers.input), the rows the step read that the
+/// peer lacks (`.fill`), after which the caller gives terminals the sizes
+/// the step gave them (`terminal.resizeDeferred`), then the unit.
fn deliver(a: *Authority, screens: *Screens, peer: u16, r: *Replica, comptime what: enum { flush, fill }) !void {
const gpa = std.testing.allocator;
var msgs: std.ArrayListUnmanaged([]u8) = .empty;
@@ -4216,7 +4191,7 @@ test "a client joined from a dump makes a `/` query's rows as the session does,
/// each peer holds as holes (`fill`), then its unit to every replica.
fn takeAll(a: *Authority, screens: *Screens, rs: []const *Replica, ps: []const u16, msg: []const u8) !void {
const gpa = std.testing.allocator;
- for (rs, ps) |r, peer| try screensTo(a, screens, peer, r);
+ for (rs, ps) |r, peer| try deliver(a, screens, peer, r, .flush);
const u = try gpa.dupe(u8, try a.take(msg));
defer gpa.free(u);
var rows: std.ArrayListUnmanaged([]u8) = .empty;