summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/replica.zig b/src/replica.zig
index b98d792b..e104391f 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -3555,7 +3555,7 @@ test "a cached blob is hashed again as it is read: one kept cut short, corrupted
try std.testing.expectEqualSlices(u8, &text, &out);
}
-test "the blob cache stays under its cap, the least recently used going first, the file compacted" {
+test "the blob cache stays under its cap, the least recently used going first and one past the cap alone without them, the file compacted" {
const io = std.testing.io;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
@@ -3583,6 +3583,15 @@ test "the blob cache stays under its cap, the least recently used going first, t
try std.testing.expect(!c.has(io, &hashes[1], 5000));
try std.testing.expect(c.has(io, &hashes[2], 5000) and c.has(io, &hashes[3], 5000));
try std.testing.expect((try std.Io.Dir.cwd().statFile(io, c.path(), .{})).size < before);
+ // The newest past the cap alone (an edited big file's text): it goes,
+ // and the older ones, which fit, stay.
+ const big: [4 * 5000]u8 = @splat('z');
+ var big_hash: [32]u8 = undefined;
+ std.crypto.hash.Blake3.hash(&big, &big_hash, .{});
+ c.put(io, &.{.{ .hash = big_hash, .bytes = &big }}, &.{});
+ c.trim(io);
+ try std.testing.expect(!c.has(io, &big_hash, big.len));
+ for ([_]usize{ 0, 2, 3 }) |k| try std.testing.expect(c.has(io, &hashes[k], 5000));
// Room for nothing: everything goes.
Cache.of(c.path(), 0).trim(io);
for (&hashes) |*h| try std.testing.expect(!c.has(io, h, 5000));