summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/replica.zig67
1 files changed, 60 insertions, 7 deletions
diff --git a/core/replica.zig b/core/replica.zig
index fb3a81c4..e2775da8 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -3142,7 +3142,9 @@ pub const Link = struct {
}
if (c.r.moved) c.dirty = true;
c.r.moved = false;
- c.changed = true;
+ // One while a check is asked is the answer's: it comes
+ // after it in the stream and its digest covers it.
+ if (!c.asked) c.changed = true;
},
.screen => |bytes| {
defer std.heap.c_allocator.free(bytes);
@@ -3212,7 +3214,12 @@ pub const Link = struct {
/// another is a divergence (the replica joins again).
fn checked(c: *Link, theirs: u64) void {
c.asked = false;
- if (!c.r.quiet() or c.r.diverged != null) return;
+ // Not quiet now, the answer is let go: it covers nothing, and the
+ // next quiet asks again.
+ if (!c.r.quiet() or c.r.diverged != null) {
+ c.changed = true;
+ return;
+ }
const mine = c.r.digest();
c.r.stats.checks += 1;
c.r.since_check = 0;
@@ -5407,11 +5414,11 @@ const walk_prefixes = prefixes: {
/// The argument a word that means nothing without one is walked with.
const walk_samples = [_]struct { []const u8, []const u8 }{
- .{ "Look", "mise.toml" }, .{ "Exec", "echo" }, .{ "Mount", "x" }, .{ "Unmount", "x" },
- .{ "Msg", "hi" }, .{ "ThemeFile", "t.zon" }, .{ "Edit", "s/a/b/" }, .{ "Mini", "x" },
- .{ "Find", "x" }, .{ "Grep", "x" }, .{ "Rename", "x" }, .{ "WsSymbols", "x" },
- .{ "Theme", "acme" }, .{ "Font", "Mono 12" }, .{ "TaglineSize", "100" }, .{ "WindowOpacity", "100" },
- .{ "MessageLinger", "1000" }, .{ "InactiveDim", "0" }, .{ "GripWidth", "100" },
+ .{ "Look", "mise.toml" }, .{ "Exec", "echo" }, .{ "Mount", "x" }, .{ "Unmount", "x" },
+ .{ "Msg", "hi" }, .{ "ThemeFile", "t.zon" }, .{ "Edit", "s/a/b/" }, .{ "Mini", "x" },
+ .{ "Find", "x" }, .{ "Grep", "x" }, .{ "Rename", "x" }, .{ "WsSymbols", "x" },
+ .{ "Theme", "acme" }, .{ "Font", "Mono 12" }, .{ "TaglineSize", "100" }, .{ "WindowOpacity", "100" },
+ .{ "MessageLinger", "1000" }, .{ "InactiveDim", "0" }, .{ "GripWidth", "100" },
};
fn keyName(buf: []u8, k: pardes.Key) []const u8 {
@@ -5830,3 +5837,49 @@ test "a far client's replay of the session's Fonts and Font takes the session's
r.settle();
try agrees(a, r);
}
+
+// An idle client asked the session's digest once quiet after a change; the
+// session's pump that answers it sends a unit before the answer (its clock
+// read), which must not count as a change, or an idle pair asks, wakes and
+// answers every 300 ms for ever. A unit while asked is the answer's to
+// cover; an answer let go (not quiet then) covers nothing.
+test "an idle client's check answered covers the units that came while it was asked: it asks no other until something changes" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false);
+ defer a.deinit();
+ const r = try joinedNow(a, 1, 0);
+ defer r.deinit();
+ var fds: [2]c_int = undefined;
+ try std.testing.expectEqual(@as(c_int, 0), libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds));
+ defer for (fds) |fd| {
+ _ = libc.close(fd);
+ };
+ var c: Link = .{ .r = r, .fd = fds[0], .now = std.time.ns_per_s };
+ const unit = struct {
+ fn of(au: *Authority) !Said {
+ return .{ .unit = try std.heap.c_allocator.dupe(u8, try au.local(.tick)) };
+ }
+ }.of;
+ // Something changed, 300 ms quiet since its last input: asked.
+ c.take(try unit(a));
+ try std.testing.expectEqual(@as(?u32, null), c.quietCheck());
+ try std.testing.expect(c.asked);
+ // The session's pump for it (a unit), then the answer: agreed, and
+ // nothing to ask after it however long it stays quiet.
+ c.take(try unit(a));
+ c.take(.{ .checked = digestOf(a) });
+ try std.testing.expect(!c.asked and c.r.diverged == null);
+ c.now.? += 10 * std.time.ns_per_s;
+ try std.testing.expectEqual(@as(?u32, null), c.quietCheck());
+ try std.testing.expect(!c.asked);
+ // A unit after it is a change again.
+ c.take(try unit(a));
+ c.now.? += std.time.ns_per_s;
+ _ = c.quietCheck();
+ try std.testing.expect(c.asked);
+ // An answer let go (an input of its own pending then) covers nothing:
+ // asked again once quiet.
+ _ = try r.pend(.{ .key = .{ .cp = 'j' } });
+ c.take(.{ .checked = digestOf(a) });
+ try std.testing.expect(!c.asked and c.changed);
+}