Skip to content

Commit

Permalink
Merge pull request #2071 from kubernetes-sigs/fix-sanity-test2
Browse files Browse the repository at this point in the history
test: don't return error when deleting rg failed in sanity test
  • Loading branch information
andyzhangx authored Aug 26, 2024
2 parents 0e0b26b + ec26726 commit 8a184ea
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 8a184ea

Please sign in to comment.