Skip to content

Commit

Permalink
Merge pull request #107 from zimnx/mz/fix-ci-tests-vet
Browse files Browse the repository at this point in the history
Run go vet and tests in all subpackages in CI
  • Loading branch information
zimnx authored Nov 14, 2022
2 parents b42f4b9 + 1b91237 commit 2a9c55a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- run: go vet
- run: go vet ./...

- name: Run unit tests
run: go test -tags unit -race
run: go test -tags unit -race ./...

- name: Install Docker compose
env:
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(), 5*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 2a9c55a

Please sign in to comment.