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

Flakes: Address TestServerStats flakiness #16991

Merged
merged 3 commits into from
Oct 18, 2024
Merged
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
20 changes: 17 additions & 3 deletions go/mysql/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ func TestServerStats(t *testing.T) {
}

timings.Reset()
connAccept.Reset()
connCount.Reset()
connAccept.Reset()
connSlow.Reset()
connRefuse.Reset()

Expand All @@ -667,9 +667,23 @@ func TestServerStats(t *testing.T) {
assert.Contains(t, output, "ERROR 1047 (08S01)")
assert.Contains(t, output, "forced query error", "Unexpected output for 'error': %v", output)

assert.EqualValues(t, 0, connCount.Get(), "connCount")
// Accept starts a goroutine to handle each incoming connection.
// It's in that goroutine where live stats/gauges such as the
// current connection counts are updated when the handle function
// ends (e.g. connCount.Add(-1)).
// So we wait for the expected value to avoid races and flakiness.
// 1 second should be enough, but no reason to fail the test or
// a CI workflow if the test is CPU starved.
conditionWait := 10 * time.Second
conditionTick := 10 * time.Millisecond
assert.Eventually(t, func() bool {
return connCount.Get() == int64(0)
}, conditionWait, conditionTick, "connCount")
assert.Eventually(t, func() bool {
return connSlow.Get() == int64(1)
}, conditionWait, conditionTick, "connSlow")

assert.EqualValues(t, 1, connAccept.Get(), "connAccept")
assert.EqualValues(t, 1, connSlow.Get(), "connSlow")
assert.EqualValues(t, 0, connRefuse.Get(), "connRefuse")

expectedTimingDeltas := map[string]int64{
Expand Down
Loading