Skip to content

Commit

Permalink
UPSTREAM: <carry>: Fix failing go vet
Browse files Browse the repository at this point in the history
Fixes following go vet failure:
* ./scylla_test.go:180:4: call to (*T).Fatal from a non-test goroutine
  • Loading branch information
zimnx committed Nov 8, 2022
1 parent f2d7f92 commit 106363c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
17 changes: 0 additions & 17 deletions scylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ type scyllaConnPicker struct {
nrShards int
msbIgnore uint64
pos uint64
dialer Dialer
lastAttemptedShard int
shardAwarePortDisabled bool

Expand Down Expand Up @@ -254,29 +253,13 @@ func newScyllaConnPicker(conn *Conn) *scyllaConnPicker {
shardAwareAddress: shardAwareAddress,
nrShards: conn.scyllaSupported.nrShards,
msbIgnore: conn.scyllaSupported.msbIgnore,
dialer: makeDialerForScyllaConnPicker(conn),
lastAttemptedShard: 0,
shardAwarePortDisabled: conn.session.cfg.DisableShardAwarePort,

disableShardAwarePortUntil: new(atomic.Value),
}
}

func makeDialerForScyllaConnPicker(conn *Conn) Dialer {
cfg := conn.session.connCfg
dialer := cfg.Dialer
if dialer == nil {
d := &ScyllaShardAwareDialer{}
d.Timeout = cfg.ConnectTimeout
if cfg.Keepalive > 0 {
d.KeepAlive = cfg.Keepalive
}
dialer = d
}

return dialer
}

func (p *scyllaConnPicker) Pick(t token) *Conn {
if len(p.conns) == 0 {
return nil
Expand Down
35 changes: 24 additions & 11 deletions scylla_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package gocql

import (
"context"
"fmt"
"math"
"runtime"
"sync"
"testing"
"time"

"github.com/gocql/gocql/internal/streams"
)
Expand Down Expand Up @@ -167,6 +169,9 @@ func TestScyllaRandomConnPIcker(t *testing.T) {
})

t.Run("async access of max iterations", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

s := &scyllaConnPicker{
nrShards: 4,
msbIgnore: 12,
Expand All @@ -175,26 +180,34 @@ func TestScyllaRandomConnPIcker(t *testing.T) {
}

var wg sync.WaitGroup
connCh := make(chan *Conn, 9)
for i := 0; i < 3; i++ {
wg.Add(1)
go pickLoop(t, s, 3, &wg)
go func() {
defer wg.Done()
for i := 0; i < 3; i++ {
select {
case connCh <- s.Pick(token(nil)):
case <-ctx.Done():
}
}
}()
}
wg.Wait()
close(connCh)

if s.pos != 8 {
t.Fatalf("expected position to be 8 | actual %d", s.pos)
}
})
}

func pickLoop(t *testing.T, s *scyllaConnPicker, c int, wg *sync.WaitGroup) {
t.Helper()
for i := 0; i < c; i++ {
if s.Pick(token(nil)) == nil {
t.Fatal("expected connection")
if len(connCh) != 9 {
t.Fatalf("expected 9 connection picks, got %d", len(connCh))
}
}
wg.Done()
for conn := range connCh {
if conn == nil {
t.Fatal("expected connection, got nil")
}
}
})
}

func TestScyllaLWTExtParsing(t *testing.T) {
Expand Down

0 comments on commit 106363c

Please sign in to comment.