MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestKeywordSuggestionCacheEviction

Function TestKeywordSuggestionCacheEviction

pkg/errors/cache_test.go:143–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func 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
179func TestKeywordSuggestionCacheConcurrency(t *testing.T) {
180 ClearSuggestionCache()

Callers

nothing calls this directly

Calls 7

ClearSuggestionCacheFunction · 0.85
SuggestKeywordFunction · 0.85
SuggestionCacheSizeFunction · 0.85
GetSuggestionCacheStatsFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected