@@ -192,6 +192,61 @@ def perform; end
192192 assert_equal 1 , SolidQueue ::Job . where ( class_name : OtherAdapterCallbackJob . name ) . count
193193 end
194194
195+ [ :finished , :failed , :destroyed ] . each do |outcome |
196+ [ SolidQueue ::Job ::EnqueueError , ActiveRecord ::Deadlocked , NameError ] . each do |error_class |
197+ test "batch completion #{ error_class } does not prevent #{ outcome } jobs from unblocking the next job" do
198+ result = JobResult . create! ( queue_name : "default" , status : "" )
199+ batch = SolidQueue ::Batch . enqueue ( on_finish : BatchCompletionJob ) do
200+ NonOverlappingUpdateResultJob . perform_later ( result , name : "A" , exception : outcome == :failed ? ExpectedTestError : nil )
201+ end
202+ job = batch . jobs . sole
203+ next_active_job = NonOverlappingUpdateResultJob . perform_later ( result , name : "B" )
204+ next_job = SolidQueue ::Job . find_by! ( active_job_id : next_active_job . job_id )
205+ process = SolidQueue ::Process . register ( kind : "Worker" , pid : 42 , name : "worker-123" )
206+ claimed_execution = SolidQueue ::ReadyExecution . claim ( job . queue_name , 1 , process . id ) . sole
207+ callback_error = error_class . new ( "batch callback failed" )
208+ events = [ ]
209+
210+ assert next_job . blocked?
211+ SolidQueue ::Batch . any_instance . stubs ( :enqueue_callback_jobs ) . raises ( callback_error )
212+
213+ SolidQueue . with ( preserve_finished_jobs : outcome != :destroyed ) do
214+ ActiveSupport ::Notifications . subscribed ( -> ( event ) { events << event } , "batch_progress_error.solid_queue" ) do
215+ if outcome == :failed
216+ assert_raises ( ExpectedTestError ) { claimed_execution . perform }
217+ else
218+ assert_nothing_raised { claimed_execution . perform }
219+ end
220+ end
221+ end
222+
223+ assert_not SolidQueue ::ClaimedExecution . exists? ( claimed_execution . id )
224+ if outcome == :destroyed
225+ assert_not SolidQueue ::Job . exists? ( job . id )
226+ else
227+ assert_equal outcome , job . reload . status
228+ end
229+ assert next_job . reload . ready?
230+ assert_not next_job . blocked?
231+ assert_equal 0 , SolidQueue ::Semaphore . find_by! ( key : job . concurrency_key ) . value
232+ assert_not batch . reload . finished?
233+ assert_empty batch . batch_executions
234+ assert_equal 0 , SolidQueue ::Job . where ( class_name : BatchCompletionJob . name ) . count
235+ assert_equal 1 , events . size
236+ assert_equal batch . id , events . sole . payload [ :batch_id ]
237+ assert_equal job . id , events . sole . payload [ :job_id ]
238+ assert_same callback_error , events . sole . payload [ :error ]
239+
240+ SolidQueue ::Batch . any_instance . unstub ( :enqueue_callback_jobs )
241+ SolidQueue ::Batch . sweep_stalled
242+
243+ assert batch . reload . finished?
244+ assert_equal outcome == :failed ? 1 : 0 , batch . failed_jobs
245+ assert_equal 1 , SolidQueue ::Job . where ( class_name : BatchCompletionJob . name ) . count
246+ end
247+ end
248+ end
249+
195250 test "assigns a reserved active_job_batch_id on create" do
196251 batch = SolidQueue ::Batch . enqueue { NiceJob . perform_later ( "world" ) }
197252
0 commit comments