@@ -26,9 +26,11 @@ class ProcessRecoveryTest < ActiveSupport::TestCase
26
26
worker_process = SolidQueue ::Process . find_by ( kind : "Worker" )
27
27
assert worker_process
28
28
29
- # Enqueue a job and manually claim it for the worker to avoid timing races
30
- job = enqueue_store_result_job ( 42 )
31
- claimed_execution = SolidQueue ::ReadyExecution . claim ( "*" , 5 , worker_process . id ) . first
29
+ # Enqueue a job and wait for it to be claimed
30
+ StoreResultJob . perform_later ( 42 , pause : 10 . seconds )
31
+ wait_while_with_timeout ( 3 . seconds ) { SolidQueue ::ClaimedExecution . none? }
32
+
33
+ claimed_execution = SolidQueue ::ClaimedExecution . last
32
34
assert claimed_execution . present?
33
35
assert_equal worker_process . id , claimed_execution . process_id
34
36
@@ -40,9 +42,8 @@ class ProcessRecoveryTest < ActiveSupport::TestCase
40
42
worker_pid = worker_process . pid
41
43
terminate_process ( worker_pid , signal : :KILL )
42
44
43
-
44
45
# Wait for the supervisor to reap the worker and fail the job
45
- wait_for_failed_executions ( 1 , timeout : 5 . seconds )
46
+ wait_while_with_timeout ( 3 . seconds ) { SolidQueue :: FailedExecution . none? }
46
47
47
48
# Assert the execution is failed
48
49
failed_execution = SolidQueue ::FailedExecution . last
@@ -53,32 +54,4 @@ class ProcessRecoveryTest < ActiveSupport::TestCase
53
54
wait_for_registered_processes ( 2 , timeout : 5 . seconds )
54
55
assert_operator SolidQueue ::Process . where ( kind : "Worker" ) . count , :>= , 1
55
56
end
56
-
57
- private
58
- def assert_registered_workers_for ( *queues , supervisor_pid : nil )
59
- workers = find_processes_registered_as ( "Worker" )
60
- registered_queues = workers . map { |process | process . metadata [ "queues" ] } . compact
61
- assert_equal queues . map ( &:to_s ) . sort , registered_queues . sort
62
- if supervisor_pid
63
- assert_equal [ supervisor_pid ] , workers . map { |process | process . supervisor . pid } . uniq
64
- end
65
- end
66
-
67
- def enqueue_store_result_job ( value , queue_name = :default , **options )
68
- StoreResultJob . set ( queue : queue_name ) . perform_later ( value , **options )
69
- end
70
-
71
- def assert_no_claimed_jobs
72
- skip_active_record_query_cache do
73
- assert_empty SolidQueue ::ClaimedExecution . all
74
- end
75
- end
76
-
77
- def wait_for_claimed_executions ( count , timeout : 1 . second )
78
- wait_for ( timeout : timeout ) { SolidQueue ::ClaimedExecution . count == count }
79
- end
80
-
81
- def wait_for_failed_executions ( count , timeout : 1 . second )
82
- wait_for ( timeout : timeout ) { SolidQueue ::FailedExecution . count == count }
83
- end
84
57
end
0 commit comments