From d54fb0885e7d9bf2d1b3fddcb02576510dce1b76 Mon Sep 17 00:00:00 2001 From: gracewilcox <43627800+gracewilcox@users.noreply.github.com> Date: Mon, 8 May 2023 09:45:32 -0700 Subject: [PATCH] [azadmin] fix flaky test (#20758) * fix flaky test * charles suggestion --- .../keyvault/azadmin/settings/client_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sdk/security/keyvault/azadmin/settings/client_test.go b/sdk/security/keyvault/azadmin/settings/client_test.go index 932444a5595c..d638eb6dad5e 100644 --- a/sdk/security/keyvault/azadmin/settings/client_test.go +++ b/sdk/security/keyvault/azadmin/settings/client_test.go @@ -8,10 +8,13 @@ package settings_test import ( "context" + "errors" "testing" + "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" "github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azadmin/settings" "github.com/stretchr/testify/require" ) @@ -103,7 +106,16 @@ func TestUpdateSetting_InvalidSettingName(t *testing.T) { require.Nil(t, res.Type) require.Nil(t, res.Value) - res, err = client.UpdateSetting(context.Background(), "invalid name", settings.UpdateSettingRequest{Value: to.Ptr("true")}, nil) + for i := 0; i < 4; i++ { + res, err = client.UpdateSetting(context.Background(), "invalid name", settings.UpdateSettingRequest{Value: to.Ptr("true")}, nil) + var httpErr *azcore.ResponseError + // if correct error is returned, break from the loop and check for correctness + if errors.As(err, &httpErr) && httpErr.StatusCode == 400 { + break + } + // else sleep for 30 seconds and try again + recording.Sleep(30 * time.Second) + } require.Error(t, err) require.Nil(t, res.Name) require.Nil(t, res.Type)