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

Function TestTokenizeContext_Timeout

pkg/sql/tokenizer/context_test.go:88–111  ·  view source on GitHub ↗

TestTokenizeContext_Timeout verifies that timeout is respected

(t *testing.T)

Source from the content-addressed store, hash-verified

86
87// TestTokenizeContext_Timeout verifies that timeout is respected
88func 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
114func TestTokenizeContext_TimeoutDuringTokenization(t *testing.T) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected