Skip to content

Commit

Permalink
Improve integration testing cloud client DeploymentIsReady. (#4798)
Browse files Browse the repository at this point in the history
Improves the logic in DeploymentIsReady to not return false and the error when it gets an error back from the API. Instead it will keep retrying until the timeout.
  • Loading branch information
blakerouse authored Jun 4, 2024
1 parent dd523c8 commit a28bc90
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/testing/ess/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
_ "embed"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -251,20 +252,19 @@ func (c *Client) DeploymentIsReady(ctx context.Context, deploymentID string, tic
ticker := time.NewTicker(tick)
defer ticker.Stop()

var errs error
statusCh := make(chan DeploymentStatus, 1)
errCh := make(chan error)

for {
select {
case <-ctx.Done():
return false, ctx.Err()
return false, errors.Join(errs, ctx.Err())
case <-ticker.C:
statusCtx, statusCancel := context.WithTimeout(ctx, tick)
defer statusCancel()
go func() {
statusCtx, statusCancel := context.WithTimeout(ctx, tick)
defer statusCancel()
status, err := c.DeploymentStatus(statusCtx, deploymentID)
if err != nil {
errCh <- err
errs = errors.Join(errs, err)
return
}
statusCh <- status.Overall
Expand All @@ -273,8 +273,6 @@ func (c *Client) DeploymentIsReady(ctx context.Context, deploymentID string, tic
if status == DeploymentStatusStarted {
return true, nil
}
case err := <-errCh:
return false, err
}
}
}
Expand Down

0 comments on commit a28bc90

Please sign in to comment.