diff options
Diffstat (limited to 'src/detached')
| -rw-r--r-- | src/detached/client.zig | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/detached/client.zig b/src/detached/client.zig index 07c85945..4769cf25 100644 --- a/src/detached/client.zig +++ b/src/detached/client.zig @@ -717,6 +717,33 @@ const Harness = struct { return error.NeverConverged; } + /// Pump until THIS frontend is showing the core's own screen, draining + /// everything that arrives on every pass. `pumpUntilSameScreen`'s reason, + /// with one frontend instead of two, and a second reason of its own: + /// `pumpUntil` returns the instant it decodes the message it was waiting + /// for and leaves the rest of that burst in the socket, so a client can sit + /// one whole frame behind for the rest of a test. Comparing once against + /// that grid compares the core's NOW with the frontend's THEN — which is + /// nothing at all until the pane shell's prompt lands in the frame nobody + /// read, and then it is a cell that differs. + /// + /// Checked BEFORE the first pump, so a test already in sync spends nothing + /// and no extra frame is manufactured to make one appear. Out of rounds it + /// hands the last comparison to `expectSameScreen`, which names the cell: + /// a transport that really does drop one must fail as a wrong screen, not + /// as a timeout. + fn pumpUntilShowsCore(h: *Harness, c: *Client) !void { + for (0..64) |_| { + _ = h.arena.reset(.retain_capacity); + if (sameScreen((try h.core.render(h.arena.allocator())).cells, c.grid.items)) return; + try h.pump(); + try c.wait(5); + while (try c.next()) |_| {} + } + _ = h.arena.reset(.retain_capacity); + return expectSameScreen((try h.core.render(h.arena.allocator())).cells, c.grid.items); + } + /// Attach a frontend and get it greeted: `open` writes the hello into the /// listener's backlog, one pump accepts and answers it. Nothing blocks, /// which is the whole reason the handshake is not a blocking call. @@ -745,10 +772,9 @@ test "detached session: a frontend attaches, is greeted, and is sent the screen" try testing.expectEqual(wire.FrameKind.full, frame.kind); try testing.expectEqual(@as(usize, 60 * 16), c.grid.items.len); // ...and it must be the core's own frame, cell for cell. This is the whole - // claim of the transport. - _ = h.arena.reset(.retain_capacity); - const surface = try h.core.render(h.arena.allocator()); - try expectSameScreen(surface.cells, c.grid.items); + // claim of the transport — asserted once the frontend has read everything + // the session sent, which `pumpUntil` above deliberately did not do. + try h.pumpUntilShowsCore(&c); } test "detached session: input from a frontend reaches the core and comes back as a diff" { @@ -766,8 +792,7 @@ test "detached session: input from a frontend reaches the core and comes back as // The change arrived as a DIFF: this frontend was already in sync, so // nothing it already had was re-sent. try testing.expectEqual(wire.FrameKind.diff, frame.kind); - _ = h.arena.reset(.retain_capacity); - try expectSameScreen((try h.core.render(h.arena.allocator())).cells, c.grid.items); + try h.pumpUntilShowsCore(&c); } test "detached session: two frontends share one screen at the smallest common grid" { |
