(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func TestKeywordSuggestionCacheEviction(t *testing.T) { |
| 144 | // Create a small cache for testing eviction |
| 145 | oldCache := suggestionCache |
| 146 | suggestionCache = newKeywordSuggestionCache(10) |
| 147 | defer func() { suggestionCache = oldCache }() |
| 148 | |
| 149 | ClearSuggestionCache() |
| 150 | ResetSuggestionCacheStats() |
| 151 | |
| 152 | // Fill the cache to max |
| 153 | for i := 0; i < 10; i++ { |
| 154 | // Generate unique inputs that won't match any keyword |
| 155 | input := string(rune('A'+i)) + "XYZQ" + string(rune('0'+i)) |
| 156 | SuggestKeyword(input) |
| 157 | } |
| 158 | |
| 159 | if SuggestionCacheSize() != 10 { |
| 160 | t.Errorf("cache size after fill = %d, want 10", SuggestionCacheSize()) |
| 161 | } |
| 162 | |
| 163 | // Add one more to trigger eviction |
| 164 | SuggestKeyword("NEWENTRY") |
| 165 | |
| 166 | // Should have evicted half (5 entries) and added 1, so size should be 6 |
| 167 | size := SuggestionCacheSize() |
| 168 | if size != 6 { |
| 169 | t.Errorf("cache size after eviction = %d, want 6", size) |
| 170 | } |
| 171 | |
| 172 | // Check eviction counter |
| 173 | stats := GetSuggestionCacheStats() |
| 174 | if stats.Evictions != 5 { |
| 175 | t.Errorf("stats.Evictions = %d, want 5", stats.Evictions) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | func TestKeywordSuggestionCacheConcurrency(t *testing.T) { |
| 180 | ClearSuggestionCache() |
nothing calls this directly
no test coverage detected