@@ -36,14 +36,7 @@ class ActiveSupport::TestCase
3636
3737 private
3838 def wait_for_jobs_to_finish_for ( timeout = 1 . second )
39- skip_active_record_query_cache do
40- Timeout . timeout ( timeout ) do
41- while SolidQueue ::Job . where ( finished_at : nil ) . any? do
42- sleep 0.05
43- end
44- end
45- end
46- rescue Timeout ::Error
39+ wait_while_with_timeout ( timeout ) { SolidQueue ::Job . where ( finished_at : nil ) . any? }
4740 end
4841
4942 def assert_no_pending_jobs
@@ -59,12 +52,7 @@ def run_supervisor_as_fork(**options)
5952 end
6053
6154 def wait_for_registered_processes ( count , timeout : 1 . second )
62- Timeout . timeout ( timeout ) do
63- while SolidQueue ::Process . count != count do
64- sleep 0.05
65- end
66- end
67- rescue Timeout ::Error
55+ wait_while_with_timeout ( timeout ) { SolidQueue ::Process . count != count }
6856 end
6957
7058 def assert_no_registered_processes
@@ -86,14 +74,27 @@ def terminate_process(pid, timeout: 10, signal: :TERM)
8674
8775 def wait_for_process_termination_with_timeout ( pid , timeout : 10 , exitstatus : 0 )
8876 Timeout . timeout ( timeout ) do
89- Process . waitpid ( pid )
90- assert exitstatus , $?. exitstatus
77+ if process_exists? ( pid )
78+ Process . waitpid ( pid )
79+ assert exitstatus , $?. exitstatus
80+ end
9181 end
9282 rescue Timeout ::Error
9383 signal_process ( pid , :KILL )
9484 raise
9585 end
9686
87+ def wait_while_with_timeout ( timeout , &block )
88+ Timeout . timeout ( timeout ) do
89+ skip_active_record_query_cache do
90+ while block . call
91+ sleep 0.05
92+ end
93+ end
94+ end
95+ rescue Timeout ::Error
96+ end
97+
9798 def signal_process ( pid , signal , wait : nil )
9899 Thread . new do
99100 sleep ( wait ) if wait
0 commit comments