From 897286f33520f45e92f37c452c987124231319f2 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Mon, 17 Nov 2025 12:00:07 +1100 Subject: [PATCH] test: fix flake in scaletest/workspaceupdates/TestRun (#20773) Closes https://github.com/coder/internal/issues/1127 In the workspace updates scaletest load generator, we end the test once all clients have seen a workspace update for their workspace. These workspace updates are generated when the workspace is created, NOT when the workspace build has finished. This means when the runner goes to clean up the workspaces, they may still be building. The runner attempts to address this by cancelling the build, but that fails with a 403 since the runner users don't have permission. The fix is to simply always wait for the build to finish, regardless of whether we were able to successfully cancel it. In this test it's probably faster to just wait for the build to finish then the overhead of cancelling it, so that's what I've gone with here. --- scaletest/workspacebuild/run.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)) }