Skip to content

Commit

Permalink
Merge db7fc5d into e0d2ce7
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleDi committed Apr 30, 2020
2 parents e0d2ce7 + db7fc5d commit 97bcbae
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -12,7 +12,7 @@ services:
- docker

before_install:
- travis_retry docker pull yandex/clickhouse-server:19.16.14.65
- travis_retry docker pull yandex/clickhouse-server:20.3.8.53
- make up_docker_server

install:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@ init:
GO111MODULE=off go get golang.org/x/lint/golint

up_docker_server: stop_docker_server
docker run --rm=true -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server:19.16.14.65;
docker run --rm=true -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server:20.3.8.53;

stop_docker_server:
test -n "$$(docker ps --format {{.Names}} | grep dbr-clickhouse-server)" && docker stop dbr-clickhouse-server || true
Expand Down
9 changes: 7 additions & 2 deletions conn.go
Expand Up @@ -16,7 +16,7 @@ import (
"sync/atomic"
"time"

uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

type key int
Expand Down Expand Up @@ -313,7 +313,12 @@ func (c *conn) buildRequest(ctx context.Context, query string, params []driver.V
}

if c.killQueryOnErr && queryID == "" {
queryID = uuid.NewV4().String()
queryUUID, err := uuid.NewV4()
if err != nil {
c.log("can't generate query_id: ", err)
} else {
queryID = queryUUID.String()
}
}

reqQuery := req.URL.Query()
Expand Down
24 changes: 17 additions & 7 deletions conn_test.go
Expand Up @@ -4,12 +4,11 @@ import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"net/http"
"testing"
"time"

uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/suite"
)

Expand Down Expand Up @@ -177,18 +176,29 @@ func (s *connSuite) TestServerError() {
}

func (s *connSuite) TestServerKillQuery() {
queryID := uuid.NewV4().String()
_, err := s.connWithKillQuery.QueryContext(context.Background(), "SELECT sleep(2)")
// kill query and check if it is cancelled
queryUUID, err := uuid.NewV4()
s.Require().NoError(err)
queryID := queryUUID.String()
_, err = s.connWithKillQuery.QueryContext(context.WithValue(context.Background(), QueryID, queryID), "SELECT sleep(3)")
s.Error(err)
s.Contains(err.Error(), "net/http: timeout awaiting response headers")
rows := s.connWithKillQuery.QueryRow(fmt.Sprintf("SELECT count(query_id) FROM system.processes where query_id='%s'", queryID))
rows := s.connWithKillQuery.QueryRow("SELECT count(query_id) FROM system.processes where query_id=? and is_cancelled=?", queryID, 1)
var amount int
err = rows.Scan(&amount)
s.NoError(err)
s.Equal(0, amount)
s.Equal(1, amount)

_, err = s.connWithKillQuery.QueryContext(context.Background(), "SELECT sleep(0.5)")
// not kill query and check if it is not cancelled
queryUUID, err = uuid.NewV4()
s.Require().NoError(err)
queryID = queryUUID.String()
_, err = s.connWithKillQuery.QueryContext(context.WithValue(context.Background(), QueryID, queryID), "SELECT sleep(0.5)")
s.NoError(err)
rows = s.connWithKillQuery.QueryRow("SELECT count(query_id) FROM system.processes where query_id=? and is_cancelled=?", queryID, 0)
err = rows.Scan(&amount)
s.NoError(err)
s.Equal(0, amount)

_, err = s.conn.QueryContext(context.Background(), "SELECT sleep(2)")
s.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,7 +1,7 @@
module github.com/mailru/go-clickhouse

require (
github.com/satori/go.uuid v1.1.0
github.com/gofrs/uuid v3.2.0+incompatible
github.com/stretchr/testify v1.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
@@ -1,9 +1,9 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/satori/go.uuid v1.1.0 h1:B9KXyj+GzIpJbV7gmr873NsY6zpbxNy24CBtGrk7jHo=
github.com/satori/go.uuid v1.1.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
Expand Down

0 comments on commit 97bcbae

Please sign in to comment.