Skip to content

Commit 2a9c55a

Browse files
authored
Merge pull request #107 from zimnx/mz/fix-ci-tests-vet
Run go vet and tests in all subpackages in CI
2 parents b42f4b9 + 1b91237 commit 2a9c55a

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
restore-keys: |
2525
${{ runner.os }}-go-
2626
27-
- run: go vet
27+
- run: go vet ./...
2828

2929
- name: Run unit tests
30-
run: go test -tags unit -race
30+
run: go test -tags unit -race ./...
3131

3232
- name: Install Docker compose
3333
env:

scylla_test.go

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package gocql
22

33
import (
4+
"context"
45
"fmt"
56
"math"
67
"runtime"
78
"sync"
89
"testing"
10+
"time"
911

1012
"github.com/gocql/gocql/internal/streams"
1113
)
@@ -167,6 +169,9 @@ func TestScyllaRandomConnPIcker(t *testing.T) {
167169
})
168170

169171
t.Run("async access of max iterations", func(t *testing.T) {
172+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
173+
defer cancel()
174+
170175
s := &scyllaConnPicker{
171176
nrShards: 4,
172177
msbIgnore: 12,
@@ -175,26 +180,34 @@ func TestScyllaRandomConnPIcker(t *testing.T) {
175180
}
176181

177182
var wg sync.WaitGroup
183+
connCh := make(chan *Conn, 9)
178184
for i := 0; i < 3; i++ {
179185
wg.Add(1)
180-
go pickLoop(t, s, 3, &wg)
186+
go func() {
187+
defer wg.Done()
188+
for i := 0; i < 3; i++ {
189+
select {
190+
case connCh <- s.Pick(token(nil)):
191+
case <-ctx.Done():
192+
}
193+
}
194+
}()
181195
}
182196
wg.Wait()
197+
close(connCh)
183198

184199
if s.pos != 8 {
185200
t.Fatalf("expected position to be 8 | actual %d", s.pos)
186201
}
187-
})
188-
}
189-
190-
func pickLoop(t *testing.T, s *scyllaConnPicker, c int, wg *sync.WaitGroup) {
191-
t.Helper()
192-
for i := 0; i < c; i++ {
193-
if s.Pick(token(nil)) == nil {
194-
t.Fatal("expected connection")
202+
if len(connCh) != 9 {
203+
t.Fatalf("expected 9 connection picks, got %d", len(connCh))
195204
}
196-
}
197-
wg.Done()
205+
for conn := range connCh {
206+
if conn == nil {
207+
t.Fatal("expected connection, got nil")
208+
}
209+
}
210+
})
198211
}
199212

200213
func TestScyllaLWTExtParsing(t *testing.T) {

0 commit comments

Comments
 (0)