Skip to content

Commit b1bf7e7

Browse files
committed
Improve reconnection policy and context handling in Queryx
1 parent 2f79f86 commit b1bf7e7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

gocqlxtest/gocqlxtest.go

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func CreateCluster() *gocql.ClusterConfig {
5151
cluster.Timeout = *flagTimeout
5252
cluster.Consistency = gocql.Quorum
5353
cluster.MaxWaitSchemaAgreement = 2 * time.Minute // travis might be slow
54+
cluster.ReconnectionPolicy = &gocql.ConstantReconnectionPolicy{
55+
MaxRetries: 10,
56+
Interval: 3 * time.Second,
57+
}
5458
if *flagRetry > 0 {
5559
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: *flagRetry}
5660
}

queryx_wrap.go

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func (q *Queryx) RoutingKey(routingKey []byte) *Queryx {
8686
// query, queries will be canceled and return once the context is
8787
// canceled.
8888
func (q *Queryx) WithContext(ctx context.Context) *Queryx {
89+
if ctx == nil {
90+
ctx = context.Background()
91+
}
8992
q.Query = q.Query.WithContext(ctx)
9093
return q
9194
}

0 commit comments

Comments
 (0)