TestTokenizeContext_ConcurrentCalls verifies thread safety with concurrent context-aware calls
(t *testing.T)
| 271 | |
| 272 | // TestTokenizeContext_ConcurrentCalls verifies thread safety with concurrent context-aware calls |
| 273 | func 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 |
| 306 | func TestTokenizeContext_BackwardCompatibility(t *testing.T) { |
nothing calls this directly
no test coverage detected