From 38ac6b92814d5c8d11fa1aeb762fe77cdabc7fbc Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:32:05 -0800 Subject: [PATCH] [release-19.0] Fix flakiness in `TestListenerShutdown` (#17024) (#17187) Signed-off-by: Florent Poinsard Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com> --- go/mysql/server_test.go | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/go/mysql/server_test.go b/go/mysql/server_test.go index 72b6f25d0c8..3c2b05c8353 100644 --- a/go/mysql/server_test.go +++ b/go/mysql/server_test.go @@ -1424,7 +1424,9 @@ func TestListenerShutdown(t *testing.T) { l.Shutdown() - waitForConnRefuse(t, 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)") @@ -1436,24 +1438,6 @@ func TestListenerShutdown(t *testing.T) { require.Equal(t, "Server shutdown in progress", sqlErr.Message) } -func waitForConnRefuse(t *testing.T, valWanted int64) { - ctx, cancel := context.WithTimeout(context.Background(), 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",