diff --git a/test/aprsme/regex_cache_test.exs b/test/aprsme/regex_cache_test.exs index 42da87d..06e9e8d 100644 --- a/test/aprsme/regex_cache_test.exs +++ b/test/aprsme/regex_cache_test.exs @@ -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