test: RegexCache LRU eviction path (100% coverage)
This commit is contained in:
parent
c020f25584
commit
cb127964ba
1 changed files with 15 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue