TestParseContext_Timeout verifies that timeout is respected
(t *testing.T)
| 122 | |
| 123 | // TestParseContext_Timeout verifies that timeout is respected |
| 124 | func TestParseContext_Timeout(t *testing.T) { |
| 125 | // Use a short timeout and wait well beyond it to guarantee expiry. |
| 126 | // Windows has ~15.6ms timer granularity, so 1ns+10ms is unreliable there. |
| 127 | // Using 1ms timeout + 100ms sleep ensures the context is expired on all platforms. |
| 128 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond) |
| 129 | defer cancel() |
| 130 | |
| 131 | // Wait long enough for the deadline to expire on all platforms (including Windows) |
| 132 | time.Sleep(100 * time.Millisecond) |
| 133 | |
| 134 | sql := "SELECT * FROM users" |
| 135 | tokens := tokenizeSQL(t, sql) |
| 136 | |
| 137 | p := NewParser() |
| 138 | defer p.Release() |
| 139 | |
| 140 | ast, err := p.ParseContext(ctx, tokens) |
| 141 | |
| 142 | // Use errors.Is for proper unwrapping - ParseContext may wrap the context error |
| 143 | if !errors.Is(err, context.DeadlineExceeded) { |
| 144 | t.Errorf("Expected context.DeadlineExceeded error, got: %v", err) |
| 145 | } |
| 146 | |
| 147 | if ast != nil { |
| 148 | t.Error("Expected nil AST when timeout expires") |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // TestParseContext_ComplexQueryWithTimeout verifies parsing complex queries with timeout |
| 153 | func TestParseContext_ComplexQueryWithTimeout(t *testing.T) { |
nothing calls this directly
no test coverage detected