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 <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2026-09-16 18:40:50 +00:00
committed by bircni
parent 699a97fc8c
commit b9c6305dee
2 changed files with 13 additions and 7 deletions
+9 -3
View File
@@ -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" {
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):
}
}
+1 -1
View File
@@ -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