Skip to content

feat: add async support for imagerunner #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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