From 975a47838b5e24904b23939a9440211e9f24ffa9 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Fri, 24 Jul 2026 18:53:35 +0200 Subject: [PATCH] Wait for the continuable job to start before interrupting it The test slept a fixed 0.2 seconds after enqueuing and then signaled TERM, assuming the job would be mid-step by then. On a slow runner the signal could arrive before any worker had even claimed the job, and the wait for released jobs would return immediately, unable to tell "released" from "never claimed", so the test asserted against a job result that hadn't been touched yet. Have the job write a "started" marker at the top of its first step and wait for it before signaling, so the interruption always lands while the job is paused inside step one, which is the scenario the test exists to check: interrupt between steps, resume, complete. Co-Authored-By: Claude Opus 4.8 --- test/dummy/app/jobs/continuable_job.rb | 1 + test/integration/continuation_test.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/dummy/app/jobs/continuable_job.rb b/test/dummy/app/jobs/continuable_job.rb index 00fdfdd24..4a7c2e2c7 100644 --- a/test/dummy/app/jobs/continuable_job.rb +++ b/test/dummy/app/jobs/continuable_job.rb @@ -11,6 +11,7 @@ class ContinuableJob < ApplicationJob def perform(result, pause: 0) step :step_one do + result.update!(queue_name: queue_name, status: "started", value: "step_one") sleep pause if pause > 0 result.update!(queue_name: queue_name, status: "stepped", value: "step_one") end diff --git a/test/integration/continuation_test.rb b/test/integration/continuation_test.rb index 8d5d863e5..708bcc6d3 100644 --- a/test/integration/continuation_test.rb +++ b/test/integration/continuation_test.rb @@ -32,7 +32,10 @@ def setup test "continuable job can be interrupted and resumed" do job = ContinuableJob.perform_later(@result, pause: 0.5.seconds) - sleep 0.2.seconds + # Wait for step_one to have started before signaling TERM, so the signal + # always arrives while the job is paused inside step_one and the interruption + # lands between the two steps + wait_while_with_timeout(3.seconds) { !JobResult.exists?(status: "started", value: "step_one") } signal_process(@pid, :TERM) wait_for_jobs_to_be_released_for(2.seconds)