@@ -195,6 +195,72 @@ class ForkedProcessesLifecycleTest < ActiveSupport::TestCase
195
195
assert_clean_termination
196
196
end
197
197
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
+
198
264
private
199
265
def assert_clean_termination
200
266
wait_for_registered_processes 0 , timeout : 0.2 . second
0 commit comments