Skip to content

Commit a02be31

Browse files
committed
Add tests to terminate and kill individual workers
1 parent eb026d3 commit a02be31

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/integration/forked_processes_lifecycle_test.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,72 @@ class ForkedProcessesLifecycleTest < ActiveSupport::TestCase
195195
assert_clean_termination
196196
end
197197

198+
test "terminate worker individually" do
199+
enqueue_store_result_job("pause", pause: 0.5.seconds)
200+
enqueue_store_result_job("pause", :default, pause: 0.5.seconds)
201+
202+
worker = find_processes_registered_as("Worker").first
203+
204+
signal_process(worker.pid, :TERM, wait: 0.1.second)
205+
206+
# Worker is gone
207+
wait_for_registered_processes(2, timeout: 3.second)
208+
assert_nil SolidQueue::Process.find_by(id: worker.id)
209+
210+
# Jobs were completed
211+
assert_completed_job_results("pause", :background)
212+
assert_completed_job_results("pause", :default)
213+
214+
# And there's a new worker that has been registered for that queue:
215+
wait_for_registered_processes(3, timeout: 3.second)
216+
assert_registered_workers_for(:background, :default)
217+
218+
# And they can process jobs just fine
219+
enqueue_store_result_job("no_pause")
220+
enqueue_store_result_job("no_pause", :default)
221+
wait_for_jobs_to_finish_for(0.2.seconds)
222+
223+
assert_completed_job_results("no_pause", :background)
224+
assert_completed_job_results("no_pause", :default)
225+
226+
terminate_process(@pid)
227+
assert_clean_termination
228+
end
229+
230+
test "kill worker individually" do
231+
killed_pause = enqueue_store_result_job("killed_pause", pause: 1.seconds)
232+
enqueue_store_result_job("pause", :default, pause: 0.5.seconds)
233+
234+
worker = find_processes_registered_as("Worker").detect { |process| process.metadata["queues"].include? "background" }
235+
236+
signal_process(worker.pid, :KILL, wait: 0.3.second)
237+
238+
# Worker didn't have time to clean up or finish the work
239+
sleep(0.7.second)
240+
assert SolidQueue::Process.exists?(id: worker.id)
241+
242+
# And there's a new worker that has been registered for the background queue
243+
wait_for_registered_processes(4, timeout: 3.second)
244+
245+
# The job in the background queue was left claimed as the worker couldn't
246+
# finish orderly
247+
assert_started_job_result("killed_pause")
248+
assert_job_status(killed_pause, :claimed)
249+
# The other one could finish
250+
assert_completed_job_results("pause", :default)
251+
252+
# The two current workers can process jobs just fine
253+
enqueue_store_result_job("no_pause")
254+
enqueue_store_result_job("no_pause", :default)
255+
wait_for_jobs_to_finish_for(0.5.seconds)
256+
257+
assert_completed_job_results("no_pause", :background)
258+
assert_completed_job_results("no_pause", :default)
259+
260+
terminate_process(@pid)
261+
assert_clean_termination
262+
end
263+
198264
private
199265
def assert_clean_termination
200266
wait_for_registered_processes 0, timeout: 0.2.second

0 commit comments

Comments
 (0)