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

Function TestTokenizeContext_ConcurrentCalls

pkg/sql/tokenizer/context_test.go:273–303  ·  view source on GitHub ↗

TestTokenizeContext_ConcurrentCalls verifies thread safety with concurrent context-aware calls

(t *testing.T)

Source from the content-addressed store, hash-verified

271
272// TestTokenizeContext_ConcurrentCalls verifies thread safety with concurrent context-aware calls
273func TestTokenizeContext_ConcurrentCalls(t *testing.T) {
274 const numGoroutines = 10
275
276 ctx := context.Background()
277 sql := "SELECT id, name, email FROM users WHERE active = true"
278
279 done := make(chan bool, numGoroutines)
280
281 for i := 0; i < numGoroutines; i++ {
282 go func(id int) {
283 tkz := GetTokenizer()
284 defer PutTokenizer(tkz)
285
286 tokens, err := tkz.TokenizeContext(ctx, []byte(sql))
287 if err != nil {
288 t.Errorf("Goroutine %d: TokenizeContext() error = %v", id, err)
289 }
290
291 if len(tokens) == 0 {
292 t.Errorf("Goroutine %d: Expected tokens but got none", id)
293 }
294
295 done <- true
296 }(i)
297 }
298
299 // Wait for all goroutines to complete
300 for i := 0; i < numGoroutines; i++ {
301 <-done
302 }
303}
304
305// TestTokenizeContext_BackwardCompatibility verifies non-context method still works
306func TestTokenizeContext_BackwardCompatibility(t *testing.T) {

Callers

nothing calls this directly

Calls 4

GetTokenizerFunction · 0.85
PutTokenizerFunction · 0.85
TokenizeContextMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected