summaryrefslogtreecommitdiff
path: root/test/behaviour/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/panes.zig')
-rw-r--r--test/behaviour/panes.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index d48ff812..9aa28c6a 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -115,3 +115,47 @@ test "panes: the pane ctl takes acme's verbs and the pane's builtins, and refuse
try std.testing.expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/ctl", .{other}), "Del\nMsg after\n"));
try std.testing.expectError(error.Refused, s.read(s.at("/pane/{d}/ctl", .{other})));
}
+
+test "panes: a second lock is refused until the holder unlocks or closes, and binds nobody else" {
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ const a = try s.hold(ctl, 2);
+ const b = try s.hold(ctl, 1);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\n"));
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\n"));
+ // Another open's lock is refused at once, and so is its unlock; writes
+ // to the pane's other files are not.
+ try std.testing.expectEqual(@as(u16, 16), try s.writeFid(b, "lock\n"));
+ try std.testing.expectEqualStrings("file in use: another open of this ctl holds the lock", s.said);
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(b, "unlock\n"));
+ try std.testing.expectEqualStrings("pane not locked by this open", s.said);
+ try s.write(s.at("/pane/{d}/addr", .{n}), "1");
+ try s.write(s.at("/pane/{d}/data", .{n}), "ONE\n");
+ try s.expect(s.at("/pane/{d}/body", .{n}), "ONE\ntwo\n");
+ // Once the holder unlocks, the other's try takes it.
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "unlock\n"));
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(b, "lock\n"));
+ try std.testing.expectEqual(@as(u16, 16), try s.writeFid(a, "lock\nunlock\n"));
+ // Closing the holder gives it up.
+ s.clunk(b);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\nunlock\nlock\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.writeFid(a, "unlock\nunlock\n"));
+ // Still a's: another open is refused it.
+ const c = try s.hold(ctl, 1);
+ try std.testing.expectEqual(@as(u16, 16), try s.writeFid(c, "lock\n"));
+ s.clunk(c);
+ // The lock lives and dies with the pane.
+ const other = try s.newPane();
+ const d = try s.hold(s.at("/pane/{d}/ctl", .{other}), 1);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(d, "lock\n"));
+ try s.write(s.at("/pane/{d}/ctl", .{other}), "Del\n");
+ try std.testing.expectEqual(@as(u16, 2), try s.writeFid(d, "lock\n"));
+ s.clunk(d);
+ s.clunk(a);
+ // a's close gave its lock up too.
+ const e = try s.hold(ctl, 1);
+ try std.testing.expectEqual(@as(u16, 0), try s.writeFid(e, "lock\n"));
+ s.clunk(e);
+}