Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: flaky multi/TestDisconnectAll #255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
package-level variable decimalPrecision (#233)
- Flaky tests TestClientRequestObjectsWithContext and
TestClientIdRequestObjectWithContext (#244)
- 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