Skip to content

Commit de97d70

Browse files
committed
fix flaky tests
1 parent f772089 commit de97d70

File tree

9 files changed

+370
-326
lines changed

9 files changed

+370
-326
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
go: [ '1.20', '1.23' ]
16+
go: [ '1.22', '1.23' ]
1717
steps:
1818
- uses: actions/checkout@v3
1919
- uses: actions/setup-go@v4
@@ -29,11 +29,11 @@ jobs:
2929
name: integration-testscontainers
3030
strategy:
3131
matrix:
32-
go: [ '1.20', '1.23' ]
32+
go: [ '1.22', '1.23' ]
3333
cassandra_version: [ '4.0.8', '4.1.1' ]
3434
auth: [ "false" ]
3535
compressor: [ "snappy" ]
36-
tags: [ "cassandra", "integration"]
36+
tags: [ "cassandra", "integration", "tc"]
3737
steps:
3838
- uses: actions/checkout@v3
3939
- uses: actions/setup-go@v4
@@ -45,15 +45,15 @@ jobs:
4545
echo "args=$args" >> $GITHUB_ENV
4646
- name: run
4747
run: |
48-
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }}
48+
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=10m -race ${{ env.args }}
4949
5050
integration-auth-testscontainers:
5151
needs: build
5252
runs-on: ubuntu-latest
5353
name: integration-auth-testscontainers
5454
strategy:
5555
matrix:
56-
go: [ '1.20', '1.23' ]
56+
go: [ '1.22', '1.23' ]
5757
cassandra_version: [ '4.0.8', '4.1.1' ]
5858
compressor: [ "snappy" ]
5959
steps:

cassandra_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ func TestBatch(t *testing.T) {
628628
}
629629

630630
func TestUnpreparedBatch(t *testing.T) {
631-
t.Skip("FLAKE skipping")
632631
session := createSession(t)
633632
defer session.Close()
634633

control_ccm_test.go

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build ccm
2-
// +build ccm
1+
//go:build tc
2+
// +build tc
33

44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one
@@ -28,17 +28,16 @@
2828
package gocql
2929

3030
import (
31+
"context"
3132
"fmt"
3233
"sync"
3334
"testing"
3435
"time"
35-
36-
"github.com/gocql/gocql/internal/ccm"
3736
)
3837

3938
type TestHostFilter struct {
4039
mu sync.Mutex
41-
allowedHosts map[string]ccm.Host
40+
allowedHosts map[string]TChost
4241
}
4342

4443
func (f *TestHostFilter) Accept(h *HostInfo) bool {
@@ -48,37 +47,27 @@ func (f *TestHostFilter) Accept(h *HostInfo) bool {
4847
return ok
4948
}
5049

51-
func (f *TestHostFilter) SetAllowedHosts(hosts map[string]ccm.Host) {
50+
func (f *TestHostFilter) SetAllowedHosts(hosts map[string]TChost) {
5251
f.mu.Lock()
5352
defer f.mu.Unlock()
5453
f.allowedHosts = hosts
5554
}
5655

5756
func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
58-
if err := ccm.AllUp(); err != nil {
59-
t.Fatal(err)
60-
}
61-
62-
allCcmHosts, err := ccm.Status()
63-
if err != nil {
64-
t.Fatal(err)
65-
}
57+
ctx := context.Background()
6658

67-
if len(allCcmHosts) < 2 {
59+
if len(cassNodes) < 2 {
6860
t.Skip("this test requires at least 2 nodes")
6961
}
7062

71-
allAllowedHosts := map[string]ccm.Host{}
72-
var firstNode *ccm.Host
73-
for _, node := range allCcmHosts {
74-
if firstNode == nil {
75-
firstNode = &node
76-
}
63+
allAllowedHosts := map[string]TChost{}
64+
for _, node := range cassNodes {
7765
allAllowedHosts[node.Addr] = node
7866
}
7967

80-
allowedHosts := map[string]ccm.Host{
81-
firstNode.Addr: *firstNode,
68+
firstNode := cassNodes["node1"]
69+
allowedHosts := map[string]TChost{
70+
firstNode.Addr: firstNode,
8271
}
8372

8473
testFilter := &TestHostFilter{allowedHosts: allowedHosts}
@@ -99,9 +88,9 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
9988
ccHost := controlConnection.host
10089

10190
var ccHostName string
102-
for _, node := range allCcmHosts {
91+
for name, node := range cassNodes {
10392
if node.Addr == ccHost.ConnectAddress().String() {
104-
ccHostName = node.Name
93+
ccHostName = name
10594
break
10695
}
10796
}
@@ -110,25 +99,15 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
11099
t.Fatal("could not find name of control host")
111100
}
112101

113-
if err := ccm.NodeDown(ccHostName); err != nil {
102+
if err := cassNodes[ccHostName].TC.Stop(ctx, nil); err != nil {
114103
t.Fatal()
115104
}
116105

117-
defer func() {
118-
ccmStatus, err := ccm.Status()
119-
if err != nil {
120-
t.Logf("could not bring nodes back up after test: %v", err)
121-
return
122-
}
123-
for _, node := range ccmStatus {
124-
if node.State == ccm.NodeStateDown {
125-
err = ccm.NodeUp(node.Name)
126-
if err != nil {
127-
t.Logf("could not bring node %v back up after test: %v", node.Name, err)
128-
}
129-
}
106+
defer func(ctx context.Context) {
107+
if err := restoreCluster(ctx); err != nil {
108+
t.Fatalf("couldn't restore a cluster : %v", err)
130109
}
131-
}()
110+
}(ctx)
132111

133112
assertNodeDown := func() error {
134113
hosts := session.ring.currentHosts()
@@ -159,19 +138,19 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
159138
}
160139

161140
if assertErr != nil {
162-
t.Fatal(err)
141+
t.Fatal(assertErr)
163142
}
164143

165144
testFilter.SetAllowedHosts(allAllowedHosts)
166145

167-
if err = ccm.NodeUp(ccHostName); err != nil {
146+
if err := restoreCluster(ctx); err != nil {
168147
t.Fatal(err)
169148
}
170149

171150
assertNodeUp := func() error {
172151
hosts := session.ring.currentHosts()
173-
if len(hosts) != len(allCcmHosts) {
174-
return fmt.Errorf("expected %v hosts in ring but there were %v", len(allCcmHosts), len(hosts))
152+
if len(hosts) != len(cassNodes) {
153+
return fmt.Errorf("expected %v hosts in ring but there were %v", len(ccHostName), len(hosts))
175154
}
176155
for _, host := range hosts {
177156
if !host.IsUp() {
@@ -181,8 +160,8 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
181160
session.pool.mu.RLock()
182161
poolsLen := len(session.pool.hostConnPools)
183162
session.pool.mu.RUnlock()
184-
if poolsLen != len(allCcmHosts) {
185-
return fmt.Errorf("expected %v connection pool but there were %v", len(allCcmHosts), poolsLen)
163+
if poolsLen != len(cassNodes) {
164+
return fmt.Errorf("expected %v connection pool but there were %v", len(ccHostName), poolsLen)
186165
}
187166
return nil
188167
}
@@ -196,6 +175,6 @@ func TestControlConn_ReconnectRefreshesRing(t *testing.T) {
196175
}
197176

198177
if assertErr != nil {
199-
t.Fatal(err)
178+
t.Fatal(assertErr)
200179
}
201180
}

0 commit comments

Comments
 (0)