@@ -125,20 +125,17 @@ class ProcessesLifecycleTest < ActiveSupport::TestCase
125125
126126 wait_while_with_timeout ( 1 . second ) { SolidQueue ::ReadyExecution . count > 0 }
127127
128- signal_process ( @pid , :TERM , wait : 0.5 )
129-
130- sleep ( SolidQueue . shutdown_timeout + 0.5 . second )
128+ signal_process ( @pid , :TERM , wait : 0.5 . second )
131129
130+ wait_while_with_timeout! ( SolidQueue . shutdown_timeout ) { not check_job_status ( no_pause , :finished ) }
132131 assert_completed_job_results ( "no pause" )
133- assert_job_status ( no_pause , :finished )
134132
135- # This job was left claimed as the worker was shutdown without
136- # a chance to terminate orderly
133+ # This job was left claimed as the worker was shutdown without a chance to terminate orderly
134+ wait_while_with_timeout! ( SolidQueue . shutdown_timeout ) { not check_job_status ( pause , :claimed ) }
137135 assert_started_job_result ( "pause" )
138- assert_job_status ( pause , :claimed )
139136
140137 # The process running the long job couldn't deregister, the other did
141- assert_registered_workers_for ( :background )
138+ wait_for_registered_processes ( 1 , timeout : 3 . seconds )
142139
143140 # Now wait until the supervisor finishes for real, which will complete the cleanup
144141 wait_for_process_termination_with_timeout ( @pid , timeout : 1 . second )
@@ -313,14 +310,18 @@ def assert_started_job_result(value, queue_name = :background, count = 1)
313310 end
314311
315312 def assert_job_status ( active_job , status )
313+ assert check_job_status ( active_job , status )
314+ end
315+
316+ def check_job_status ( active_job , status )
316317 # Make sure we skip AR query cache. Otherwise the queries done here
317318 # might be cached and since we haven't done any non-SELECT queries
318319 # after they were cached on the connection used in the test, the cache
319320 # will still apply, even though the data returned by the cached queries
320321 # might have been deleted in the forked processes.
321322 skip_active_record_query_cache do
322323 job = SolidQueue ::Job . find_by ( active_job_id : active_job . job_id )
323- assert job . public_send ( "#{ status } ?" )
324+ job . public_send ( "#{ status } ?" )
324325 end
325326 end
326327end
0 commit comments