From 62ca0a75518a394bb6c35b620a9e8ee62beb38a8 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 2 Jan 2026 16:08:07 -0800 Subject: [PATCH] avoid stderr output in zig build test/move test to Lru --- src/cache/Cache.zig | 30 ------------------------------ src/cache/Lru.zig | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/cache/Cache.zig b/src/cache/Cache.zig index a06c6ac..da66510 100644 --- a/src/cache/Cache.zig +++ b/src/cache/Cache.zig @@ -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); -} diff --git a/src/cache/Lru.zig b/src/cache/Lru.zig index c4a8d19..53d7d9e 100644 --- a/src/cache/Lru.zig +++ b/src/cache/Lru.zig @@ -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); +}