Skip to content

Commit

Permalink
fix: poll query bug (#120)
Browse files Browse the repository at this point in the history
* fix: poll query bug

* add test
  • Loading branch information
hantmac committed May 23, 2024
1 parent 40f8f5c commit 73ce824
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,10 @@ func (c *APIClient) applySessionState(response *QueryResponse) {
}

func (c *APIClient) PollUntilQueryEnd(ctx context.Context, resp *QueryResponse) (*QueryResponse, error) {
var err error
for !resp.ReadFinished() {
data := resp.Data
resp, err := c.PollQuery(ctx, resp.NextURI)
resp, err = c.PollQuery(ctx, resp.NextURI)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"context"
"database/sql"
"encoding/json"
"fmt"
Expand All @@ -9,6 +10,7 @@ import (
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/test-go/testify/suite"

Expand Down Expand Up @@ -327,6 +329,20 @@ func (s *DatabendTestSuite) TestTransactionRollback() {
s.r.NoError(rows.Close())
}

func (s *DatabendTestSuite) TestLongExec() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

_, err := s.db.ExecContext(ctx, "SELECT number from numbers(100000) order by number")
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
s.T().Errorf("Query execution exceeded the 10s timeout")
} else {
s.r.Nil(err)
}
}
}

func scanValues(rows *sql.Rows) (interface{}, error) {
var err error
var result [][]interface{}
Expand Down

0 comments on commit 73ce824

Please sign in to comment.