diff options
Diffstat (limited to 'test/replicas.zig')
| -rw-r--r-- | test/replicas.zig | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/test/replicas.zig b/test/replicas.zig index 0f23d5a8..5e49a3ac 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -608,7 +608,52 @@ fn plumbCase(dir: []const u8) !bool { ok = false; } }; - std.debug.print("plumb: a URL and a commit hash looked at by the authority and as a replica's own input: {s}\n", .{if (ok) "the same session" else "FAILED"}); + // A rule to a port a program reads (plumb/seemail), of a URL, which a + // look reads no disk for: whether the port is read is the authority's + // 9P state, asked through the tape. A replica's own look waits for the + // first answer, then guesses the last; the second look speculates whole + // and is confirmed with no rollback. + { + // The rule from the session's plumbing file, read at boot. + var pbuf: [256]u8 = undefined; + try writeText(try std.fmt.bufPrintSentinel(&pbuf, "{s}/plumbing", .{dir}, 0), "type is text\ndata matches 'https://letters/.*'\nplumb to seemail\n\ninclude basic\n"); + const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty, .config_dir = dir }, host.host(), true); + defer a.deinit(); + const first = try gpa.dupe(u8, try a.unit(0, 0)); + defer gpa.free(first); + const rp = try replica.Replica.init(gpa, 1, first, true); + defer rp.deinit(); + rp.confirm(try a.local(.{ .command = open })); + rp.settle(); + if (pardes.Plumb.portIndex(rp.core(), "seemail") == null) { + std.debug.print("plumb: a look to a port: the plumbing file's port is not the replica's\n", .{}); + ok = false; + } + for (0..2) |n| { + const before = rp.stats; + const msg = try gpa.dupe(u8, try rp.input(.{ .command = "Look https://letters/42" })); + defer gpa.free(msg); + if (n == 1 and (rp.stats.stopped != before.stopped or rp.stats.speculated == before.speculated)) { + std.debug.print("plumb: a look to a port: the replica's second look did not speculate whole ({d} stopped, {d} applied)\n", .{ rp.stats.stopped - before.stopped, rp.stats.speculated - before.speculated }); + ok = false; + } + if (try a.pending()) |batch| rp.confirm(batch); + rp.confirm(try a.take(msg)); + rp.settle(); + } + if (rp.diverged) |why| { + std.debug.print("plumb: a look to a port: the replica diverged: {s}\n", .{why}); + ok = false; + } else if (!rp.quiet() or rp.digest() != replica.digestOf(a)) { + std.debug.print("plumb: a look to a port: the replica's digest is not the authority's\n", .{}); + ok = false; + } + if (rp.stats.mispredicted + rp.stats.foreign != 0) { + std.debug.print("plumb: a look to a port: {d} rollbacks\n", .{rp.stats.mispredicted + rp.stats.foreign}); + ok = false; + } + } + std.debug.print("plumb: a URL, a commit hash and a look to a port read by programs, by the authority and as a replica's own input: {s}\n", .{if (ok) "the same session" else "FAILED"}); return ok; } |
