diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 12:24:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 12:47:01 -0300 |
| commit | 1b5e4b3eaa5a25d98e41b20c13af15565b03c93f (patch) | |
| tree | dd7f7afa4c300eee453dcdf116d63cbcd6433569 /src | |
| parent | 7753126756dd6a8dc371fa200e6ba84b3c0eb6f2 (diff) | |
| download | pardes-1b5e4b3eaa5a25d98e41b20c13af15565b03c93f.tar.gz pardes-1b5e4b3eaa5a25d98e41b20c13af15565b03c93f.zip | |
replica: the two tests that count a replica's fast confirmations start early in a second: an edit's file time is the clock's second, which the replica guesses, so a second's turn between a key and the authority's take of it was a misprediction (another client's input first: expected 4 fast, found 3, in 11 runs of 40 of a loaded Debug window build)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/replica.zig | 15 |
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 |
