Skip to content

Commit

Permalink
Flakes: Address TestServerStats flakiness (#16991)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord authored Oct 18, 2024
1 parent e881b9f commit 3360865
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit 3360865

Please sign in to comment.