summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 02141f44..d6a2e0ef 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -2818,6 +2818,19 @@ const TestHost = struct {
}
};
+/// An edit's file time is the clock's second, which a replica guesses: a
+/// second's turn between a key and the authority's take of it is a fair
+/// misprediction (11 runs in 40 of a loaded Debug window build's test
+/// below). The tests that count fast confirmations start early in a second.
+fn freshSecond() void {
+ while (true) {
+ var ts: std.c.timespec = undefined;
+ if (std.c.clock_gettime(.REALTIME, &ts) != 0 or ts.nsec < 50 * std.time.ns_per_ms) return;
+ const rest: std.c.timespec = .{ .sec = 0, .nsec = std.time.ns_per_s - ts.nsec };
+ _ = std.c.nanosleep(&rest, null);
+ }
+}
+
fn key(r: *Replica, cp: u21, sent: *std.ArrayListUnmanaged([]u8)) !void {
const text = [_]u8{@intCast(cp & 0x7f)};
const msg = try r.input(.{ .key = .{ .cp = cp, .text = if (cp < 0x80 and cp >= 0x20) &text else "" } });
@@ -2836,6 +2849,7 @@ test "a replica's own keys apply at once, confirm on the fast path, and end at t
for (sent.items) |m| gpa.free(m);
sent.deinit(gpa);
}
+ freshSecond();
for ("oabc") |k| try key(r, k, &sent);
try key(r, pardes.Key.escape, &sent);
try std.testing.expectEqual(@as(usize, 5), r.applied);
@@ -2868,6 +2882,7 @@ test "another client's input first: a replica rolls back, replays it and applies
s1.deinit(gpa);
s2.deinit(gpa);
}
+ freshSecond();
for ("oone") |k| try key(r1, k, &s1);
for ("Otwo") |k| try key(r2, k, &s2);
// The authority hears r2 first, then r1; both hear the units in that