Skip to content

Commit

Permalink
Some fixups for helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeler committed Jun 15, 2023
1 parent 40d3e73 commit 237b748
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 6 additions & 0 deletions build-support/scripts/check-allowed-imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ function main {
esac
done

# If we could guarantee this ran with bash 4.2+ then the final argument could
# be just ${allowed_packages[@]}. However that with older versions of bash
# in combination with set -u causes bash to emit errors about using unbound
# variables when no allowed packages have been specified (i.e. the module should
# generally be disallowed with no exceptions). This syntax is very strange
# but seems to be the prescribed workaround I found.
check_imports "$module_root" ${allowed_packages[@]+"${allowed_packages[@]}"}
return $?
}
Expand Down
6 changes: 3 additions & 3 deletions internal/resource/resourcetest/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func (b *resourceBuilder) Write(t T, client pbresource.ResourceServiceClient) *p

if strings.Contains(err.Error(), storage.ErrWrongUid.Error()) {
r.Fatalf("resource write failed due to uid mismatch - most likely a transient issue when talking to a non-leader")
} else {
// other errors are unexpected and should cause an immediate failure
r.Stop(err)
}
// other failed precondition errors will be checked outside of the retry
})

require.NoError(t, err)

if !b.dontCleanup {
cleaner, ok := t.(CleanupT)
require.True(t, ok, "T does not implement a Cleanup method and cannot be used with automatic resource cleanup")
Expand Down
12 changes: 4 additions & 8 deletions internal/resource/resourcetest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/exp/slices"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)

type Client struct {
Expand Down Expand Up @@ -84,7 +83,7 @@ func (client *Client) PublishResources(t T, resources []*pbresource.Resource) {

cleaner, ok := t.(CleanupT)
if ok {
id := proto.Clone(rsp.Resource.Id).(*pbresource.ID)
id := rsp.Resource.Id
cleaner.Cleanup(func() {
client.MustDelete(t, id)
})
Expand Down Expand Up @@ -237,22 +236,19 @@ func (client *Client) ResolveResourceID(t T, id *pbresource.ID) *pbresource.ID {
}

func (client *Client) MustDelete(t T, id *pbresource.ID) {

client.retry(t, func(r *retry.R) {
_, err := client.Delete(context.Background(), &pbresource.DeleteRequest{Id: id})
if status.Code(err) == codes.NotFound {
return
}

// codes.Aborted indicates a CAS failure and that the delete request should
// be retried. Anything else should be considered an unrecoverable error.
if err != nil && status.Code(err) != codes.Aborted {
r.Stop(fmt.Errorf("failed to delete the resource: %w", err))
}

require.NoError(r, err)
})
// _, err := client.Delete(context.Background(), &pbresource.DeleteRequest{Id: id})
// if status.Code(err) == codes.NotFound {
// return
// }

// require.NoError(t, err)
}

0 comments on commit 237b748

Please sign in to comment.