diff options
| -rw-r--r-- | core/replica.zig | 49 | ||||
| -rw-r--r-- | core/tape.zig | 10 |
2 files changed, 51 insertions, 8 deletions
diff --git a/core/replica.zig b/core/replica.zig index 8fd0a251..b4d8edfa 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -963,9 +963,10 @@ pub const Replica = struct { r.last_digest.clearRetainingCapacity(); if (ends) |d| r.last_digest.appendSlice(r.gpa, d) catch {}; } - // A terminal's output is never taken so (the one rule): what it - // writes outside the copy is applied once, at its place, and much - // of it no digest covers (a colour set, a mode). + // A terminal's output, or a join's reloads, never taken so (the one + // rule): what it writes outside the copy is applied once, at its + // place, and much of it no digest covers (a colour set, a mode, the + // pages a reload remakes). if (r.applied > 0 and u.origin != r.id and ends != null and std.mem.eql(u8, ends.?, r.last_digest.items) and (r.t.screen_state or !tape.feedsTerminal(u.tape))) { @@ -3295,8 +3296,9 @@ pub const Link = struct { fn checked(c: *Link, theirs: u64) void { c.asked = false; // 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) { + // next quiet asks again. Nor once its link is let go: a lag's let-go + // drops the units after it (`lags`), and the core is behind them. + if (c.quit or !c.r.quiet() or c.r.diverged != null) { c.changed = true; return; } @@ -4445,6 +4447,39 @@ test "bytes: a client joins from a dump with its terminals whole, and every side try sameTerminals(b.a, late); } +test "bytes: a join refused for want of a view reloads every terminal and moves nothing a digest covers: a client with a key on top reloads too, at its place, never taking that unit as moving nothing" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const b = try BytesPair.init(); + defer b.deinit(); + try b.output("a line of the program's\r\n"); + // Every view taken: the session's, then three clients'. + for (2..pardes.views.max + 1) |client| b.r.confirm((try b.a.openView(@intCast(client))).unit); + try b.output("and one since the last join\r\n"); + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + // A key of its own on top; a fifth client refused, its step reloading + // every terminal in the unit of the pump the others take next; the key + // confirmed; the program prints on. + try key(b.r, 'l', &sent); + try std.testing.expectEqual(@as(usize, 1), b.r.applied); + const before = pardes.Term.reloads.n; + try std.testing.expect(try b.a.join(pardes.views.max + 1, null) == null); + const session = pardes.Term.reloads.n - before; + try std.testing.expect(session > 0); + b.a.pump(); + b.r.confirm((try b.a.pending()).?); + b.r.confirm(try b.a.take(sent.items[0])); + b.r.settle(); + try b.output("and on\r\n"); + try std.testing.expectEqual(2 * session, pardes.Term.reloads.n - before); + try agrees(b.a, b.r); + try sameTerminals(b.a, b.r); +} + test "bytes: a session's output past a unit's bound is cut into units under it, between two reads" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; @@ -5116,6 +5151,10 @@ test "a client whose session's units come more than two seconds later than its q try std.testing.expect(!link.quit); try Late.take(&link, a, 1_100, 8_300); try std.testing.expect(link.quit); + // A check answered after it let go, behind the unit it let go of: its + // core is behind on purpose, no divergence. + link.take(.{ .checked = digestOf(a) +% 1 }); + try std.testing.expect(r.diverged == null); try std.testing.expect(link.rejoins()); try std.testing.expectEqualStrings("joined again: 2.1 s behind", link.notice()); try std.testing.expect(!link.rejoins()); diff --git a/core/tape.zig b/core/tape.zig index d977b53e..ea1a5691 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1520,15 +1520,19 @@ pub fn endSpeculation(t: *Tape) bool { /// a message may be (replica.zig `lag_max`'s neighbour, wire's bound). pub const unit_max = 1 << 20; -/// Whether a unit feeds a terminal its program's output (a pty's read; an -/// input kept by hash is taken to): never taken as moving nothing (the -/// replica engine's one rule, core/replica.zig `confirm`). +/// Whether a unit writes a terminal's emulator: feeds one its program's +/// output (a pty's read; an input kept by hash is taken to), or reloads +/// every one at a join (`Site.reload`; a join refused too, which moves +/// nothing a digest covers): never taken as moving nothing (the replica +/// engine's one rule, core/replica.zig `confirm`). pub fn feedsTerminal(bytes: []const u8) bool { const Tag = std.meta.Tag(Input); const EventTag = std.meta.Tag(pardes.Event); + const reload: u16 = @as(u16, host_fns.len) + @backingInt(Site.reload); var r: walk.Reader = .{ .bytes = bytes }; while (nextRecord(&r)) |rec| switch (rec.kind) { .blob => if (rec.payload.len > 0 and rec.payload[0] == @backingInt(Kind.input)) return true, + .host => if (rec.payload.len >= 2 and std.mem.bytesToValue(u16, rec.payload[0..2]) == reload) return true, .input => { if (rec.payload.len < @sizeOf(Tag) + @sizeOf(EventTag)) continue; if (!std.mem.eql(u8, rec.payload[0..@sizeOf(Tag)], std.mem.asBytes(&@as(Tag, .update)))) continue; |
