diff --git a/scaletest/workspacebuild/run.go b/scaletest/workspacebuild/run.go index f05173c688..fd3f1be54b 100644 --- a/scaletest/workspacebuild/run.go +++ b/scaletest/workspacebuild/run.go @@ -147,12 +147,12 @@ func (r *CleanupRunner) Run(ctx context.Context, _ string, logs io.Writer) error if err == nil && build.Job.Status.Active() { // mark the build as canceled logger.Info(ctx, "canceling workspace build", slog.F("build_id", build.ID), slog.F("workspace_id", r.workspaceID)) - if err = r.client.CancelWorkspaceBuild(ctx, build.ID, codersdk.CancelWorkspaceBuildParams{}); err == nil { - // Wait for the job to cancel before we delete it - _ = waitForBuild(ctx, logs, r.client, build.ID) // it will return a "build canceled" error - } else { - logger.Warn(ctx, "failed to cancel workspace build, attempting to delete anyway", slog.Error(err)) + if err = r.client.CancelWorkspaceBuild(ctx, build.ID, codersdk.CancelWorkspaceBuildParams{}); err != nil { + logger.Warn(ctx, "failed to cancel workspace build", slog.Error(err)) } + // Wait for either the build or the cancellation to finish + // either is necessary or we'll fail at the delete step. + _ = waitForBuild(ctx, logs, r.client, build.ID) // it will return a "build canceled" error } else { logger.Warn(ctx, "unable to lookup latest workspace build, attempting to delete anyway", slog.Error(err)) }