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

Function TestKeywordSuggestionCacheConcurrency

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

Source from the content-addressed store, hash-verified

177}
178
179func TestKeywordSuggestionCacheConcurrency(t *testing.T) {
180 ClearSuggestionCache()
181
182 var wg sync.WaitGroup
183 inputs := []string{"SELCT", "WHRE", "FRMO", "JION", "ORDR"}
184
185 // Run multiple goroutines concurrently
186 for i := 0; i < 100; i++ {
187 wg.Add(1)
188 go func(idx int) {
189 defer wg.Done()
190 input := inputs[idx%len(inputs)]
191 _ = SuggestKeyword(input)
192 }(i)
193 }
194
195 wg.Wait()
196
197 // Cache should have at most len(inputs) entries
198 size := SuggestionCacheSize()
199 if size > len(inputs) {
200 t.Errorf("cache size = %d, want <= %d", size, len(inputs))
201 }
202}
203
204func BenchmarkSuggestKeywordWithCache(b *testing.B) {
205 ClearSuggestionCache()

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected