Skip to content

Commit

Permalink
fix: revert to previous behaviod polling forever
Browse files Browse the repository at this point in the history
The ctx passed into WaitForTaskToSucceed is only used to cancel HTTP reqests and not to cancel the wait.
  • Loading branch information
dkoshkin committed Jan 5, 2024
1 parent 298cfdd commit 9c533b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const (
)

// WaitForTaskToSucceed will poll indefinitely every 2 seconds for the task with uuid to have status of "SUCCEEDED".
// Returns an error from GetTaskStatus or a timeout error if the context is cancelled.
// The polling will not stop if the ctx is cancelled, it's only used for HTTP requests in the client.
// WaitForTaskToSucceed will exit immediately on an error getting the task.
func WaitForTaskToSucceed(ctx context.Context, conn *nutanixClientV3.Client, uuid string) error {
return wait.PollImmediateInfiniteWithContext(ctx, pollingInterval, func(ctx context.Context) (done bool, err error) {
return wait.PollImmediateInfinite(pollingInterval, func() (done bool, err error) {
status, getErr := GetTaskStatus(ctx, conn, uuid)
return status == statusSucceeded, getErr
})
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/wait"

nutanixtestclient "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/test/helpers/prism-go-client/v3"
)
Expand Down Expand Up @@ -127,7 +126,7 @@ func Test_WaitForTaskCompletion(t *testing.T) {
fmt.Fprint(w, `{"status": "PENDING"}`)
},
ctx: ctx,
expectedErr: wait.ErrWaitTimeout,
expectedErr: context.DeadlineExceeded,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 9c533b8

Please sign in to comment.