Skip to content

Commit

Permalink
Fix flakiness in TestListenerShutdown (#17024)
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui authored Nov 8, 2024
1 parent 0eb27b2 commit 2d1e96a
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions go/mysql/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,9 @@ func TestListenerShutdown(t *testing.T) {

l.Shutdown()

waitForConnRefuse(t, ctx, 1)
require.Eventually(t, func() bool {
return connRefuse.Get() == 1
}, 1*time.Minute, 100*time.Millisecond, "could not reach the desired connRefuse value")

err = conn.Ping()
require.EqualError(t, err, "Server shutdown in progress (errno 1053) (sqlstate 08S01)")
Expand All @@ -1426,24 +1428,6 @@ func TestListenerShutdown(t *testing.T) {
require.Equal(t, "Server shutdown in progress", sqlErr.Message)
}

func waitForConnRefuse(t *testing.T, ctx context.Context, valWanted int64) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
tick := time.NewTicker(100 * time.Millisecond)
defer tick.Stop()

for {
select {
case <-ctx.Done():
require.FailNow(t, "connRefuse did not reach %v", valWanted)
case <-tick.C:
if connRefuse.Get() == valWanted {
return
}
}
}
}

func TestParseConnAttrs(t *testing.T) {
expected := map[string]string{
"_client_version": "8.0.11",
Expand Down

0 comments on commit 2d1e96a

Please sign in to comment.