0
0
mirror of https://gitlab.com/cznic/sqlite.git synced 2025-05-17 23:26:41 +00:00

fix error handling in test "QueryContext with context expiring"

While the query had succeeded, the context can expire right after. In
this situation, iterating the rows will fail. The test need to check for
sql.Rows.Err() too.

Also, don't forget to close sql.Rows when done to avoid memory leak.
This commit is contained in:
Romain LE DISEZ
2024-02-22 13:31:53 +00:00
parent f925b4f354
commit 0a8da4bb8f

@ -794,12 +794,21 @@ func TestRegisteredFunctions(t *testing.T) {
}()
for start := time.Now(); time.Since(start) < 200*time.Millisecond; {
rows, err := conn.QueryContext(ctx, "select count(*) from t")
if err != nil && !(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), "interrupted (9)")) {
tt.Fatalf("unexpected error, was expected context or interrupted error: err=%v", err)
} else if err == nil && !rows.Next() {
tt.Fatalf("success with no data (try=%d)", try)
}
func() {
rows, err := conn.QueryContext(ctx, "select count(*) from t")
if rows != nil {
defer rows.Close()
}
if err != nil && !(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), "interrupted (9)")) {
tt.Fatalf("unexpected error, was expected context or interrupted error: err=%v", err)
} else if err == nil && !rows.Next() {
if rowsErr := rows.Err(); rowsErr != nil && !(errors.Is(rowsErr, context.Canceled) || errors.Is(rowsErr, context.DeadlineExceeded) || strings.Contains(rowsErr.Error(), "interrupted (9)")) {
tt.Fatalf("unexpected error, was expected context or interrupted error: err=%v", err)
} else if rowsErr == nil {
tt.Fatalf("success with no data (try=%d)", try)
}
}
}()
}
}
})