@@ -26,6 +26,8 @@ def write(...)
2626Logger ::LogDevice . prepend ( BlockLogDeviceTimeoutExceptions )
2727
2828class ActiveSupport ::TestCase
29+ include ProcessesTestHelper , JobsTestHelper
30+
2931 teardown do
3032 JobBuffer . clear
3133
@@ -43,57 +45,6 @@ class ActiveSupport::TestCase
4345 end
4446
4547 private
46- def wait_for_jobs_to_finish_for ( timeout = 1 . second , except : [ ] )
47- wait_while_with_timeout ( timeout ) do
48- SolidQueue ::Job . where . not ( active_job_id : Array ( except ) . map ( &:job_id ) ) . where ( finished_at : nil ) . any?
49- end
50- end
51-
52- def assert_no_unfinished_jobs
53- skip_active_record_query_cache do
54- assert SolidQueue ::Job . where ( finished_at : nil ) . none?
55- end
56- end
57-
58- def run_supervisor_as_fork ( **options )
59- fork do
60- SolidQueue ::Supervisor . start ( mode : :fork , **options )
61- end
62- end
63-
64- def wait_for_registered_processes ( count , timeout : 1 . second )
65- wait_while_with_timeout ( timeout ) { SolidQueue ::Process . count != count }
66- end
67-
68- def assert_no_registered_processes
69- skip_active_record_query_cache do
70- assert SolidQueue ::Process . none?
71- end
72- end
73-
74- def find_processes_registered_as ( kind )
75- skip_active_record_query_cache do
76- SolidQueue ::Process . where ( kind : kind )
77- end
78- end
79-
80- def terminate_process ( pid , timeout : 10 , signal : :TERM )
81- signal_process ( pid , signal )
82- wait_for_process_termination_with_timeout ( pid , timeout : timeout )
83- end
84-
85- def wait_for_process_termination_with_timeout ( pid , timeout : 10 , exitstatus : 0 )
86- Timeout . timeout ( timeout ) do
87- if process_exists? ( pid )
88- Process . waitpid ( pid )
89- assert exitstatus , $?. exitstatus
90- end
91- end
92- rescue Timeout ::Error
93- signal_process ( pid , :KILL )
94- raise
95- end
96-
9748 def wait_while_with_timeout ( timeout , &block )
9849 wait_while_with_timeout! ( timeout , &block )
9950 rescue Timeout ::Error
@@ -109,26 +60,6 @@ def wait_while_with_timeout!(timeout, &block)
10960 end
11061 end
11162
112- def signal_process ( pid , signal , wait : nil )
113- Thread . new do
114- sleep ( wait ) if wait
115- Process . kill ( signal , pid )
116- end
117- end
118-
119- def process_exists? ( pid )
120- reap_processes
121- Process . getpgid ( pid )
122- true
123- rescue Errno ::ESRCH
124- false
125- end
126-
127- def reap_processes
128- Process . waitpid ( -1 , Process ::WNOHANG )
129- rescue Errno ::ECHILD
130- end
131-
13263 # Allow skipping AR query cache, necessary when running test code in multiple
13364 # forks. The queries done in the test might be cached and if we don't perform
13465 # any non-SELECT queries after previous SELECT queries were cached on the connection
0 commit comments