test: RegexCache LRU eviction path (100% coverage)

This commit is contained in:
Graham McIntire 2026-04-24 08:23:51 -05:00
parent c020f25584
commit cb127964ba
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -69,5 +69,20 @@ defmodule Aprsme.RegexCacheTest do
assert {:ok, %Regex{}} = RegexCache.get_or_compile(p)
end
end
test "exercises LRU eviction when cache grows past the max-size threshold" do
# Generate enough patterns to push past @max_cache_size (1000).
# Existing cache entries count too, so overshoot by ~150 to be safe.
patterns = for i <- 1..1_200, do: "lru_pattern_#{System.unique_integer()}_#{i}"
for p <- patterns do
assert {:ok, %Regex{}} = RegexCache.get_or_compile(p)
end
# The first few patterns should likely be evicted, but still compile fine
# on re-request (no caching contract violation).
[first | _] = patterns
assert {:ok, %Regex{}} = RegexCache.get_or_compile(first)
end
end
end