summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig62
1 files changed, 58 insertions, 4 deletions
diff --git a/core/replica.zig b/core/replica.zig
index bc5eafd1..13c1fe46 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5353,10 +5353,7 @@ const may_wait = [_]Wait{
.{ .what = "DumpConfig", .on = .any, .stop = "the authority's own state", .why = "the config file written" },
.{ .what = "ThemeFile *", .on = .any, .stop = "the authority's own state", .why = "a theme file, the session's" },
.{ .what = "DumpThemes", .on = .any, .stop = "the authority's own state", .why = "the theme files written" },
- // A search's rows: the session's worker or its loop writes them, and
- // whether it has a worker is not the client's to know (12a); a
- // +Preview's text is read from the session's disk.
- .{ .what = "Search *", .on = .any, .stop = "search", .why = "a search's rows, the session's worker's" },
+ // A +Preview's text is read from the session's disk.
.{ .what = "Search *", .on = .any, .stop = "preview", .why = "a +Preview's file, from the session's disk" },
// A kind's own state on the session (a PDF's document): asking it.
.{ .what = "*", .on = .addon, .stop = "a kind's search", .why = "a search in a kind's pane: its own state, the session's" },
@@ -6277,3 +6274,60 @@ test "a client joined from a dump lands a click on a rail's tick as the session
try agrees(a, r);
try std.testing.expectEqual(a.core.panes[owner].?.places.current, r.core().panes[owner].?.places.current);
}
+
+// `search` stopped every client's step that asked for one, because a host
+// with no worker wrote the rows outside any record: then no client had them,
+// stopped or not (a replay answers the entry from the tape and runs no
+// host). Its rows are inputs now, as a worker's are, and a step that asks
+// the session's host for a search goes on.
+test "a far client's step that asks for a search goes on at once, and a session whose host searches on its loop gives every client its rows" {
+ // A session's host with no worker for a search (a frontend before its
+ // threads, or one whose worker could not be had: Stream.start): it runs
+ // the search on its loop, in its `search` entry.
+ const LoopSearch = struct {
+ var core: ?*Pardes = null;
+ fn search(_: ?*anyopaque, gen: u32) void {
+ pardes.Stream.runHere(core.?, gen, true);
+ }
+ fn now(_: ?*anyopaque) u64 {
+ var ts: std.c.timespec = undefined;
+ _ = std.c.clock_gettime(.MONOTONIC, &ts);
+ return @intCast(ts.sec * std.time.ns_per_s + ts.nsec);
+ }
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search, .now = now };
+ };
+ const gpa = std.testing.allocator;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.zig", .data = "const needle = 1;\nfn f() void {}\n// a needle\n" });
+ var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var path_buf: [std.Io.Dir.max_path_bytes + 8]u8 = undefined;
+ const path = try std.fmt.bufPrint(&path_buf, "{s}/a.zig", .{dir});
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = path }, .{ .vtable = &LoopSearch.vtable }, false);
+ defer a.deinit();
+ LoopSearch.core = a.core;
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ // A `/` in a file asks the session's host for its parse.
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = "Search /ne" }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try agrees(a, r);
+ // A Grep the session's loop runs when the typing pauses: its rows.
+ r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } }));
+ r.confirm(try a.local(.{ .command = "Search Grep needle" }));
+ r.settle();
+ var ticks: u32 = 0;
+ while (a.core.stream.state == .waiting) : (ticks += 1) {
+ if (ticks == 200) return error.Timeout;
+ const rest: std.c.timespec = .{ .sec = 0, .nsec = 10 * std.time.ns_per_ms };
+ _ = std.c.nanosleep(&rest, null);
+ r.confirm(try a.local(.tick));
+ r.settle();
+ }
+ try std.testing.expect(a.core.stream.state == .done);
+ try agrees(a, r);
+}