Skip to content

Commit

Permalink
feat: add async support for imagerunner
Browse files Browse the repository at this point in the history
  • Loading branch information
alexplischke committed Oct 5, 2023
1 parent 5f17154 commit 8ca67ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/cmd/run/imagerunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func runImageRunner(cmd *cobra.Command) (int, error) {
Reporters: []report.Reporter{&table.Reporter{
Dst: os.Stdout,
}},
Async: gFlags.async,
}
return r.RunProject()
}
Expand Down
18 changes: 14 additions & 4 deletions internal/saucecloud/imagerunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type ImgRunner struct {

Reporters []report.Reporter

Async bool

ctx context.Context
cancel context.CancelFunc
}
Expand Down Expand Up @@ -260,6 +262,12 @@ func (r *ImgRunner) runSuite(suite imagerunner.Suite) (imagerunner.Runner, error

log.Info().Str("image", suite.Image).Str("suite", suite.Name).Str("runID", runner.ID).
Msg("Started suite.")

if r.Async {
// Async mode means we don't wait for the suite to finish.
return runner, nil
}

run, err = r.PollRun(ctx, runner.ID, runner.Status)
if errors.Is(err, context.DeadlineExceeded) && ctx.Err() != nil {
// Use a new context, because the suite's already timed out, and we'd not be able to stop the run.
Expand Down Expand Up @@ -307,12 +315,14 @@ func (r *ImgRunner) collectResults(results chan execResult, expected int) bool {
passed = false
}

log.Err(res.err).Str("suite", res.name).Bool("passed", res.err == nil).Str("runID", res.runID).
Msg("Suite finished.")
if imagerunner.Done(res.status) {
log.Err(res.err).Str("suite", res.name).Bool("passed", res.err == nil).Str("runID", res.runID).
Msg("Suite finished.")

r.PrintLogs(res.runID, res.name)
r.PrintLogs(res.runID, res.name)

r.DownloadArtifacts(res.runID, res.name, res.status, passed)
r.DownloadArtifacts(res.runID, res.name, res.status, passed)
}

for _, r := range r.Reporters {
r.Add(report.TestResult{
Expand Down

0 comments on commit 8ca67ac

Please sign in to comment.