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

MM-27957: Fix flaky test TestRecycleDBConns #15415

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions store/sqlstore/supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,22 @@ func TestRecycleDBConns(t *testing.T) {
assert.Equal(t, 0, int(stats.MaxLifetimeClosed), "unexpected number of connections closed due to maxlifetime")

supplier.RecycleDBConnections(2 * time.Second)
// We cannot reliably control exactly how many open connections are there. So we
// just do a basic check and confirm that atleast one has been closed.
stats = supplier.GetMaster().Db.Stats()
assert.Greater(t, int(stats.MaxLifetimeClosed), 0, "unexpected number of connections closed due to maxlifetime")
var success bool
// We try 3 times to let the connections be closed.
// Because sometimes, there can be significant goroutine contention which does not
// give enough time for the connection cleaner goroutine to run.
for i := 0; i < 3; i++ {
// We cannot reliably control exactly how many open connections are there. So we
// just do a basic check and confirm that atleast one has been closed.
stats = supplier.GetMaster().Db.Stats()
if int(stats.MaxLifetimeClosed) == 0 {
time.Sleep(2 * time.Second)
continue
}
success = true
break
}
assert.True(t, success, "No connections were closed due to maxlifetime")
})
}
}
Expand Down