From 95ca0f5c2973705bb9557c2dedd6cf7aedcb867e Mon Sep 17 00:00:00 2001 From: Fuad Hasan Date: Wed, 29 Jan 2025 14:40:13 +0600 Subject: [PATCH 1/2] Enhance cluster configuration with reconnection policy and improve context handling in Queryx --- gocqlxtest/gocqlxtest.go | 5 +++++ queryx_wrap.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/gocqlxtest/gocqlxtest.go b/gocqlxtest/gocqlxtest.go index 26cb6690..52175114 100644 --- a/gocqlxtest/gocqlxtest.go +++ b/gocqlxtest/gocqlxtest.go @@ -50,7 +50,12 @@ func CreateCluster() *gocql.ClusterConfig { cluster.CQLVersion = *flagCQL cluster.Timeout = *flagTimeout cluster.Consistency = gocql.Quorum + //cluster.NumConns = 2 // might be useful for testing cluster.MaxWaitSchemaAgreement = 2 * time.Minute // travis might be slow + cluster.ReconnectionPolicy = &gocql.ConstantReconnectionPolicy{ + MaxRetries: 10, + Interval: 3 * time.Second, + } if *flagRetry > 0 { cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: *flagRetry} } diff --git a/queryx_wrap.go b/queryx_wrap.go index e63bb4a2..08a98df2 100644 --- a/queryx_wrap.go +++ b/queryx_wrap.go @@ -86,6 +86,9 @@ func (q *Queryx) RoutingKey(routingKey []byte) *Queryx { // query, queries will be canceled and return once the context is // canceled. func (q *Queryx) WithContext(ctx context.Context) *Queryx { + if ctx == nil { + ctx = context.Background() + } q.Query = q.Query.WithContext(ctx) return q } From 88db241c851a8272c709ed71e8eea734edc18979 Mon Sep 17 00:00:00 2001 From: Fuad Hasan Date: Wed, 29 Jan 2025 15:04:42 +0600 Subject: [PATCH 2/2] Remove commented-out NumConns setting in CreateCluster function --- gocqlxtest/gocqlxtest.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gocqlxtest/gocqlxtest.go b/gocqlxtest/gocqlxtest.go index 52175114..d4b648ca 100644 --- a/gocqlxtest/gocqlxtest.go +++ b/gocqlxtest/gocqlxtest.go @@ -50,7 +50,6 @@ func CreateCluster() *gocql.ClusterConfig { cluster.CQLVersion = *flagCQL cluster.Timeout = *flagTimeout cluster.Consistency = gocql.Quorum - //cluster.NumConns = 2 // might be useful for testing cluster.MaxWaitSchemaAgreement = 2 * time.Minute // travis might be slow cluster.ReconnectionPolicy = &gocql.ConstantReconnectionPolicy{ MaxRetries: 10,