Skip to content

Commit b0956f3

Browse files
committed
bugfix: flaky multi/TestDisconnectAll
After the fix the test stops tarantool intances to avoid concurrent reconnects by a ConnectionMulti instance. Closes #234
1 parent 41532b6 commit b0956f3

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2525
package-level variable decimalPrecision (#233)
2626
- Flaky tests TestClientRequestObjectsWithContext and
2727
TestClientIdRequestObjectWithContext (#244)
28+
- Flaky test multi/TestDisconnectAll (#234)
2829

2930
## [1.9.0] - 2022-11-02
3031

multi/multi_test.go

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var connOptsMulti = OptsMulti{
3131
ClusterDiscoveryTime: 3 * time.Second,
3232
}
3333

34+
var instances []test_helpers.TarantoolInstance
35+
3436
func TestConnError_IncorrectParams(t *testing.T) {
3537
multiConn, err := Connect([]string{}, tarantool.Opts{})
3638
if err == nil {
@@ -118,36 +120,41 @@ func TestReconnect(t *testing.T) {
118120
}
119121

120122
func TestDisconnectAll(t *testing.T) {
121-
multiConn, _ := Connect([]string{server1, server2}, connOpts)
123+
sleep := 100 * time.Millisecond
124+
sleepCnt := int((time.Second / sleep) * 2) // Checkout time * 2.
125+
126+
servers := []string{server1, server2}
127+
multiConn, _ := Connect(servers, connOpts)
122128
if multiConn == nil {
123129
t.Errorf("conn is nil after Connect")
124130
return
125131
}
126-
timer := time.NewTimer(300 * time.Millisecond)
127-
<-timer.C
128-
defer multiConn.Close()
129132

130-
conn, _ := multiConn.getConnectionFromPool(server1)
131-
conn.Close()
132-
conn, _ = multiConn.getConnectionFromPool(server2)
133-
conn.Close()
133+
for _, inst := range instances {
134+
test_helpers.StopTarantoolWithCleanup(inst)
135+
}
136+
137+
for i := 0; i < sleepCnt && multiConn.ConnectedNow(); i++ {
138+
time.Sleep(sleep)
139+
}
134140

135141
if multiConn.ConnectedNow() {
136142
t.Errorf("incorrect status after desconnect all")
137143
}
138144

139-
timer = time.NewTimer(100 * time.Millisecond)
140-
<-timer.C
141-
if !multiConn.ConnectedNow() {
142-
t.Errorf("incorrect multiConn status after reconnecting")
145+
for _, inst := range instances {
146+
err := test_helpers.RestartTarantool(&inst)
147+
if err != nil {
148+
t.Fatalf("failed to restart Tarantool: %s", err)
149+
}
143150
}
144-
conn, _ = multiConn.getConnectionFromPool(server1)
145-
if !conn.ConnectedNow() {
146-
t.Errorf("incorrect server1 conn status after reconnecting")
151+
152+
for i := 0; i < sleepCnt && !multiConn.ConnectedNow(); i++ {
153+
time.Sleep(sleep)
147154
}
148-
conn, _ = multiConn.getConnectionFromPool(server2)
149-
if !conn.ConnectedNow() {
150-
t.Errorf("incorrect server2 conn status after reconnecting")
155+
156+
if !multiConn.ConnectedNow() {
157+
t.Errorf("incorrect multiConn status after reconnecting")
151158
}
152159
}
153160

@@ -589,36 +596,23 @@ func runTestMain(m *testing.M) int {
589596
log.Fatalf("Could not check the Tarantool version")
590597
}
591598

592-
inst1, err := test_helpers.StartTarantool(test_helpers.StartOpts{
599+
servers := []string{server1, server2}
600+
instances, err = test_helpers.StartTarantoolInstances(servers, nil, test_helpers.StartOpts{
593601
InitScript: initScript,
594-
Listen: server1,
595602
User: connOpts.User,
596603
Pass: connOpts.Pass,
597604
WaitStart: waitStart,
598605
ConnectRetry: connectRetry,
599606
RetryTimeout: retryTimeout,
600607
MemtxUseMvccEngine: !isStreamUnsupported,
601608
})
602-
defer test_helpers.StopTarantoolWithCleanup(inst1)
603609

604610
if err != nil {
605611
log.Fatalf("Failed to prepare test tarantool: %s", err)
612+
return -1
606613
}
607614

608-
inst2, err := test_helpers.StartTarantool(test_helpers.StartOpts{
609-
InitScript: initScript,
610-
Listen: server2,
611-
User: connOpts.User,
612-
Pass: connOpts.Pass,
613-
WaitStart: waitStart,
614-
ConnectRetry: connectRetry,
615-
RetryTimeout: retryTimeout,
616-
})
617-
defer test_helpers.StopTarantoolWithCleanup(inst2)
618-
619-
if err != nil {
620-
log.Fatalf("Failed to prepare test tarantool: %s", err)
621-
}
615+
defer test_helpers.StopTarantoolInstances(instances)
622616

623617
return m.Run()
624618
}

0 commit comments

Comments
 (0)