Skip to content

Commit

Permalink
test: don't return error when deleting rg failed in sanity test
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
andyzhangx authored and k8s-infra-cherrypick-robot committed Aug 26, 2024
1 parent 89d9261 commit 12d22c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func WaitUntilTimeout(timeout time.Duration, execFunc ExecFunc, timeoutFunc Time
done := make(chan bool)
var err error

// Start the azcopy exec function in a goroutine
// Start exec function in a goroutine
go func() {
err = execFunc()
done <- true
Expand Down
2 changes: 1 addition & 1 deletion test/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestSanity(t *testing.T) {
if strings.HasPrefix(creds.ResourceGroup, credentials.ResourceGroupPrefix) {
log.Printf("Deleting resource group %s", creds.ResourceGroup)
err := azureClient.DeleteResourceGroup(ctx, creds.ResourceGroup)
assert.NoError(t, err)
log.Printf("Deleted resource group %s failed with error %v", creds.ResourceGroup, err)
}
}()

Expand Down
23 changes: 17 additions & 6 deletions test/utils/azure/azure_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,24 @@ func (az *Client) EnsureResourceGroup(ctx context.Context, name, location string

func (az *Client) DeleteResourceGroup(ctx context.Context, groupName string) error {
_, err := az.groupsClient.Get(ctx, groupName)
if err == nil {
err := az.groupsClient.Delete(ctx, groupName)
if err != nil {
return fmt.Errorf("cannot delete resource group %v: %v", groupName, err)
}
if err != nil {
return err
}

timeout := 20 * time.Minute
ch := make(chan bool, 1)

go func() {
err = az.groupsClient.Delete(ctx, groupName)
ch <- true
}()

select {
case <-ch:
return err
case <-time.After(timeout):
return fmt.Errorf("timeout waiting for resource group %s to be deleted", groupName)
}
return nil
}

func (az *Client) EnsureVirtualMachine(ctx context.Context, groupName, location, vmName string) (vm *compute.VirtualMachine, err error) {
Expand Down

0 comments on commit 12d22c2

Please sign in to comment.