Skip to content

Commit

Permalink
test: attempt number on two on proper retries in CLI time tests
Browse files Browse the repository at this point in the history
See #4702

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
(cherry picked from commit c297d66)
  • Loading branch information
smira committed Jan 21, 2022
1 parent c1c5d9e commit ba39f68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/integration/base/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (cliSuite *CLISuite) buildCLICmd(args []string) *exec.Cmd {

// RunCLI runs talosctl binary with the options provided.
func (cliSuite *CLISuite) RunCLI(args []string, options ...RunOption) (stdout string) {
return run(&cliSuite.Suite, cliSuite.buildCLICmd(args), options...)
return run(&cliSuite.Suite, func() *exec.Cmd { return cliSuite.buildCLICmd(args) }, options...)
}

// RunAndWaitForMatch retries command until output matches.
Expand Down
10 changes: 5 additions & 5 deletions internal/integration/base/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func runAndWait(suite *suite.Suite, cmd *exec.Cmd) (stdoutBuf, stderrBuf *bytes.
}

// retryRunAndWait retries runAndWait if the command fails to run.
func retryRunAndWait(suite *suite.Suite, cmd *exec.Cmd, retryer retry.Retryer) (stdoutBuf, stderrBuf *bytes.Buffer, err error) {
func retryRunAndWait(suite *suite.Suite, cmdFunc func() *exec.Cmd, retryer retry.Retryer) (stdoutBuf, stderrBuf *bytes.Buffer, err error) {
err = retryer.Retry(func() error {
stdoutBuf, stderrBuf, err = runAndWait(suite, cmd)
stdoutBuf, stderrBuf, err = runAndWait(suite, cmdFunc())

if _, ok := err.(*exec.ExitError); ok {
return retry.ExpectedError(err)
Expand All @@ -168,7 +168,7 @@ func retryRunAndWait(suite *suite.Suite, cmd *exec.Cmd, retryer retry.Retryer) (
// run executes command, asserts on its exit status/output, and returns stdout.
//
//nolint:gocyclo,nakedret
func run(suite *suite.Suite, cmd *exec.Cmd, options ...RunOption) (stdout string) {
func run(suite *suite.Suite, cmdFunc func() *exec.Cmd, options ...RunOption) (stdout string) {
var opts runOptions

for _, o := range options {
Expand All @@ -181,9 +181,9 @@ func run(suite *suite.Suite, cmd *exec.Cmd, options ...RunOption) (stdout string
)

if opts.retryer != nil {
stdoutBuf, stderrBuf, err = retryRunAndWait(suite, cmd, opts.retryer)
stdoutBuf, stderrBuf, err = retryRunAndWait(suite, cmdFunc, opts.retryer)
} else {
stdoutBuf, stderrBuf, err = runAndWait(suite, cmd)
stdoutBuf, stderrBuf, err = runAndWait(suite, cmdFunc())
}

if err != nil {
Expand Down

0 comments on commit ba39f68

Please sign in to comment.