From b9c6305dee26938c32b19597c87fb665cd73d499 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 16 Sep 2026 18:40:50 +0000 Subject: [PATCH] test: stop the cancellation e2e test racing the job it watches (#1230) `waitForRunningJobLog` gave one minute to run creation, scheduling, the container start and the first log flush, then blamed the missing log line, which is how https://gitea.com/gitea/runner/actions/runs/927661 failed. It now gets the suite's `runTimeout` and reports the job's status with the run logs on timeout, and the job holds ten seconds instead of two, so neither the marker nor the cancellation arrives after it has exited. Against gitea 1.28+ this costs nothing, since the cancel ends the job as soon as the marker appears. Against 1.27, which has no cancel route and waits the job out, the suite goes from about 20s to about 23s, as the tests run in parallel. *Written by Claude.* Reviewed-on: https://gitea.com/gitea/runner/pulls/1230 Reviewed-by: bircni Co-authored-by: silverwind --- e2e/cancel_test.go | 18 ++++++++++++------ e2e/testdata/workflows/cancel.yml | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/e2e/cancel_test.go b/e2e/cancel_test.go index 24416e53..2c06bd29 100644 --- a/e2e/cancel_test.go +++ b/e2e/cancel_test.go @@ -51,23 +51,29 @@ func testRunCancellation(t *testing.T) { func waitForRunningJobLog(t *testing.T, api *GiteaAPI, repo string, runID int64, substr string) { t.Helper() - ctx, cancel := context.WithTimeout(t.Context(), time.Minute) + // The budget covers scheduling and the container start, which a loaded runner makes slow. + ctx, cancel := context.WithTimeout(t.Context(), runTimeout) defer cancel() + status := "none" for { jobs, err := api.Jobs(ctx, repo, runID) if err != nil { t.Fatalf("list jobs: %v", err) } - if len(jobs) > 0 && jobs[0].Status == "in_progress" { - logs, err := api.JobLogs(ctx, repo, jobs[0].ID) - if err == nil && commandRow(logs, substr) == substr { - return + if len(jobs) > 0 { + status = jobs[0].Status + if status == "in_progress" { + logs, err := api.JobLogs(ctx, repo, jobs[0].ID) + if err == nil && commandRow(logs, substr) == substr { + return + } } } select { case <-ctx.Done(): - t.Fatalf("running job for run %d never logged %q", runID, substr) + dumpRunLogs(t, api, repo, runID) + t.Fatalf("job of run %d is %q and never logged %q", runID, status, substr) case <-time.After(pollInterval): } } diff --git a/e2e/testdata/workflows/cancel.yml b/e2e/testdata/workflows/cancel.yml index 61db8ab5..9d022e6b 100644 --- a/e2e/testdata/workflows/cancel.yml +++ b/e2e/testdata/workflows/cancel.yml @@ -6,4 +6,4 @@ jobs: steps: - run: | echo e2e-live-log-marker - timeout 2s tail -f /dev/null || true + timeout 10s tail -f /dev/null || true