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

Function TestParseContext_Timeout

pkg/sql/parser/context_test.go:124–150  ·  view source on GitHub ↗

TestParseContext_Timeout verifies that timeout is respected

(t *testing.T)

Source from the content-addressed store, hash-verified

122
123// TestParseContext_Timeout verifies that timeout is respected
124func 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
153func TestParseContext_ComplexQueryWithTimeout(t *testing.T) {

Callers

nothing calls this directly

Calls 6

ReleaseMethod · 0.95
ParseContextMethod · 0.95
tokenizeSQLFunction · 0.85
NewParserFunction · 0.70
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected