TestTokenizeContext_Timeout verifies that timeout is respected
(t *testing.T)
| 86 | |
| 87 | // TestTokenizeContext_Timeout verifies that timeout is respected |
| 88 | func TestTokenizeContext_Timeout(t *testing.T) { |
| 89 | // Use a very short timeout that should expire before processing large input |
| 90 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) |
| 91 | defer cancel() |
| 92 | |
| 93 | // Give the timeout time to expire |
| 94 | time.Sleep(10 * time.Millisecond) |
| 95 | |
| 96 | tkz := GetTokenizer() |
| 97 | defer PutTokenizer(tkz) |
| 98 | |
| 99 | // Create a large SQL query to ensure processing takes time |
| 100 | sql := "SELECT " + strings.Repeat("column1, column2, column3, ", 1000) + "column_final FROM table" |
| 101 | |
| 102 | tokens, err := tkz.TokenizeContext(ctx, []byte(sql)) |
| 103 | |
| 104 | if err != context.DeadlineExceeded { |
| 105 | t.Errorf("Expected context.DeadlineExceeded error, got: %v", err) |
| 106 | } |
| 107 | |
| 108 | if tokens != nil { |
| 109 | t.Error("Expected nil tokens when timeout expires") |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // TestTokenizeContext_TimeoutDuringTokenization verifies cancellation during active tokenization |
| 114 | func TestTokenizeContext_TimeoutDuringTokenization(t *testing.T) { |
nothing calls this directly
no test coverage detected