Skip to content

Commit

Permalink
[azadmin] fix flaky test (#20758)
Browse files Browse the repository at this point in the history
* fix flaky test

* charles suggestion
  • Loading branch information
gracewilcox authored May 8, 2023
1 parent 0cbfd88 commit d54fb08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sdk/security/keyvault/azadmin/settings/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d54fb08

Please sign in to comment.