Skip to content

Commit

Permalink
bugfix: flaky multi/TestDisconnectAll
Browse files Browse the repository at this point in the history
After the fix the test stops tarantool intances to avoid concurrent
reconnects by a ConnectionMulti instance.

Closes #234
  • Loading branch information
oleg-jukovec committed Dec 27, 2022
1 parent a1f28a6 commit 272a347
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

- Decimal package uses a test variable DecimalPrecision instead of a
package-level variable decimalPrecision (#233)
- Flaky test multi/TestDisconnectAll (#234)

## [1.9.0] - 2022-11-02

Expand Down
64 changes: 29 additions & 35 deletions multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var connOptsMulti = OptsMulti{
ClusterDiscoveryTime: 3 * time.Second,
}

var instances []test_helpers.TarantoolInstance

func TestConnError_IncorrectParams(t *testing.T) {
multiConn, err := Connect([]string{}, tarantool.Opts{})
if err == nil {
Expand Down Expand Up @@ -118,36 +120,41 @@ func TestReconnect(t *testing.T) {
}

func TestDisconnectAll(t *testing.T) {
multiConn, _ := Connect([]string{server1, server2}, connOpts)
sleep := 100 * time.Millisecond
sleepCnt := int((time.Second / sleep) * 2) // Checkout time * 2.

servers := []string{server1, server2}
multiConn, _ := Connect(servers, connOpts)
if multiConn == nil {
t.Errorf("conn is nil after Connect")
return
}
timer := time.NewTimer(300 * time.Millisecond)
<-timer.C
defer multiConn.Close()

conn, _ := multiConn.getConnectionFromPool(server1)
conn.Close()
conn, _ = multiConn.getConnectionFromPool(server2)
conn.Close()
for _, inst := range instances {
test_helpers.StopTarantoolWithCleanup(inst)
}

for i := 0; i < sleepCnt && multiConn.ConnectedNow(); i++ {
time.Sleep(sleep)
}

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

timer = time.NewTimer(100 * time.Millisecond)
<-timer.C
if !multiConn.ConnectedNow() {
t.Errorf("incorrect multiConn status after reconnecting")
for _, inst := range instances {
err := test_helpers.RestartTarantool(&inst)
if err != nil {
t.Fatalf("failed to restart Tarantool: %s", err)
}
}
conn, _ = multiConn.getConnectionFromPool(server1)
if !conn.ConnectedNow() {
t.Errorf("incorrect server1 conn status after reconnecting")

for i := 0; i < sleepCnt && !multiConn.ConnectedNow(); i++ {
time.Sleep(sleep)
}
conn, _ = multiConn.getConnectionFromPool(server2)
if !conn.ConnectedNow() {
t.Errorf("incorrect server2 conn status after reconnecting")

if !multiConn.ConnectedNow() {
t.Errorf("incorrect multiConn status after reconnecting")
}
}

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

inst1, err := test_helpers.StartTarantool(test_helpers.StartOpts{
servers := []string{server1, server2}
instances, err = test_helpers.StartTarantoolInstances(servers, nil, test_helpers.StartOpts{
InitScript: initScript,
Listen: server1,
User: connOpts.User,
Pass: connOpts.Pass,
WaitStart: waitStart,
ConnectRetry: connectRetry,
RetryTimeout: retryTimeout,
MemtxUseMvccEngine: !isStreamUnsupported,
})
defer test_helpers.StopTarantoolWithCleanup(inst1)

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

inst2, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: initScript,
Listen: server2,
User: connOpts.User,
Pass: connOpts.Pass,
WaitStart: waitStart,
ConnectRetry: connectRetry,
RetryTimeout: retryTimeout,
})
defer test_helpers.StopTarantoolWithCleanup(inst2)

if err != nil {
log.Fatalf("Failed to prepare test tarantool: %s", err)
}
defer test_helpers.StopTarantoolInstances(instances)

return m.Run()
}
Expand Down

0 comments on commit 272a347

Please sign in to comment.