avoid stderr output in zig build test/move test to Lru

This commit is contained in:
Emil Lerch 2026-01-02 16:08:07 -08:00
parent 2a841b9779
commit 62ca0a7551
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 15 additions and 30 deletions

30
src/cache/Cache.zig vendored
View file

@ -275,33 +275,3 @@ test "L1/L2 cache flow" {
// Now it should be in L1
try std.testing.expectEqualStrings("value1", cache.lru.get("key1").?);
}
test "expired cache entry returns null" {
const allocator = std.testing.allocator;
var tmp_dir = std.testing.tmpDir(.{});
defer tmp_dir.cleanup();
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
const cache_dir = try tmp_dir.dir.realpath(".", &path_buf);
const cache = try Cache.init(allocator, .{ .max_entries = 10, .cache_dir = cache_dir });
defer cache.deinit();
// Put item with past expiration time
const now = std.time.milliTimestamp();
const past_expires = now - 1000;
// Manually insert expired entry into L1
const key_copy = try allocator.dupe(u8, "key1");
const value_copy = try allocator.dupe(u8, "value1");
try cache.lru.map.put(key_copy, .{
.value = value_copy,
.expires = past_expires,
.access_count = 0,
});
// Get should return null for expired entry
const result = cache.get("key1");
try std.testing.expect(result == null);
}

15
src/cache/Lru.zig vendored
View file

@ -137,3 +137,18 @@ test "LRU eviction" {
try std.testing.expect(lru.get("key1") == null);
}
test "LRU expired entry returns null" {
var lru = try Lru.init(std.testing.allocator, 10);
defer lru.deinit();
// Put item with past expiration time
const now = std.time.milliTimestamp();
const past_expires = now - 1000;
try lru.put("key1", "value1", past_expires);
// Get should return null for expired entry
const result = lru.get("key1");
try std.testing.expect(result == null);
}