Skip to content

Commit e16ff38

Browse files
mattlordarthurschreiber
authored andcommitted
Flakes: Address TestServerStats flakiness (#16991)
Signed-off-by: Matt Lord <mattalord@gmail.com> (cherry picked from commit 9290e31)
1 parent 384182b commit e16ff38

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

go/mysql/server_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ func TestServerStats(t *testing.T) {
654654
}
655655

656656
timings.Reset()
657-
connAccept.Reset()
658657
connCount.Reset()
658+
connAccept.Reset()
659659
connSlow.Reset()
660660
connRefuse.Reset()
661661

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

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

675689
expectedTimingDeltas := map[string]int64{

0 commit comments

Comments
 (0)