From cb127964baca169921e53b7cc7426534a8e76dde Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:23:51 -0500 Subject: [PATCH] test: RegexCache LRU eviction path (100% coverage) --- test/aprsme/regex_cache_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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