Skip to content

Commit 4ff226e

Browse files
committed
Avoid busy waiting and an infinite loop in serial worker spec
1 parent dca5e50 commit 4ff226e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

spec/integration/workers/serial_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,16 @@ def self.perform(job)
224224
jid: 'jid', retries: 10)
225225
run_jobs(worker, 1) do
226226
redis.brpop(key, timeout: 1).should eq([key.to_s, 'foo'])
227-
# FIXME: this seems to get into infinite loop sometimes
228-
until client.jobs['jid'].state == 'waiting'; end
227+
# Wait for job to transition to 'waiting' state with timeout protection
228+
max_attempts = 500 # 5 seconds with 10ms intervals
229+
attempts = 0
230+
until client.jobs['jid'].state == 'waiting'
231+
attempts += 1
232+
if attempts > max_attempts
233+
raise "Job never reached 'waiting' state. Current state: #{client.jobs['jid'].state}"
234+
end
235+
sleep 0.01
236+
end
229237
end
230238
expect(client.jobs['jid'].retries_left).to be < 10
231239
end

0 commit comments

Comments
 (0)