From 73f540dc9415ba398672ab014dff876c2e9a24ff Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Fri, 4 Aug 2023 19:42:21 -0400 Subject: [PATCH] kv: deflake TestAdminDecommissionedOperations by setting server.shutdown.query_wait Fixes #107875. This commit deflakes `TestAdminDecommissionedOperations` by setting the `server.shutdown.query_wait` cluster setting to 0s. This ensures that SQL queries are immediately cancelled during the drain, instead of being let run for up to 10s (the previous test timeout) before cancellation. The commit also increases the timeouts in the test to the default `testutils` timeouts, to avoid flakes when CI is slow. Release note: None --- pkg/server/storage_api/decommission_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/server/storage_api/decommission_test.go b/pkg/server/storage_api/decommission_test.go index 1395a0cdea74..20b1a8f2adf6 100644 --- a/pkg/server/storage_api/decommission_test.go +++ b/pkg/server/storage_api/decommission_test.go @@ -785,6 +785,9 @@ func TestAdminDecommissionedOperations(t *testing.T) { }) defer tc.Stopper().Stop(ctx) + // Configure drain to immediately cancel SQL queries and jobs to speed up the + // test and avoid timeouts. + serverutils.SetClusterSetting(t, tc, "server.shutdown.query_wait", 0) serverutils.SetClusterSetting(t, tc, "server.shutdown.jobs_wait", 0) scratchKey := tc.ScratchRange(t) @@ -801,8 +804,8 @@ func TestAdminDecommissionedOperations(t *testing.T) { require.NoError(t, srv.Decommission(ctx, status, []roachpb.NodeID{decomSrv.NodeID()})) } - testutils.SucceedsWithin(t, func() error { - timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second) + testutils.SucceedsSoon(t, func() error { + timeoutCtx, cancel := context.WithTimeout(ctx, testutils.DefaultSucceedsSoonDuration) defer cancel() _, err := decomSrv.DB().Scan(timeoutCtx, keys.LocalMax, keys.MaxKey, 0) if err == nil { @@ -813,7 +816,7 @@ func TestAdminDecommissionedOperations(t *testing.T) { return nil } return err - }, 10*time.Second) + }) // Set up an admin client. adminClient := decomSrv.GetAdminClient(t) @@ -925,8 +928,8 @@ func TestAdminDecommissionedOperations(t *testing.T) { for _, tc := range testcases { tc := tc t.Run(tc.name, func(t *testing.T) { - testutils.SucceedsWithin(t, func() error { - timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second) + testutils.SucceedsSoon(t, func() error { + timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() err := tc.op(timeoutCtx, adminClient) if tc.expectCode == codes.OK { @@ -945,7 +948,7 @@ func TestAdminDecommissionedOperations(t *testing.T) { } require.Equal(t, tc.expectCode, s.Code(), "%+v", err) return nil - }, 10*time.Second) + }) }) } }