@@ -62,7 +62,9 @@ class WorkerTest < ActiveSupport::TestCase
6262 @worker . wake_up
6363
6464 assert_equal 1 , subscriber . errors . count
65- assert_equal "everything is broken" , subscriber . messages . first
65+ error = subscriber . errors . first . first
66+ assert_instance_of SolidQueue ::ClaimedExecution ::FinalizationError , error
67+ assert_equal "everything is broken" , error . cause . message
6668 ensure
6769 Rails . error . unsubscribe ( subscriber ) if Rails . error . respond_to? ( :unsubscribe )
6870 SolidQueue . on_thread_error = original_on_thread_error
@@ -85,6 +87,41 @@ class WorkerTest < ActiveSupport::TestCase
8587 Rails . error . unsubscribe ( subscriber ) if Rails . error . respond_to? ( :unsubscribe )
8688 end
8789
90+ test "worker stops and releases the claim when finishing a job fails" do
91+ previous_on_thread_error , SolidQueue . on_thread_error = SolidQueue . on_thread_error , -> ( *) { }
92+
93+ SolidQueue ::ClaimedExecution . any_instance . stubs ( :finished ) . raises ( ActiveRecord ::StatementInvalid . new ( "transient DB glitch" ) )
94+
95+ AddToBufferJob . perform_later "hey!"
96+
97+ @worker . start
98+
99+ wait_while_with_timeout ( 2 . seconds ) { !@worker . pool . shutdown? }
100+ assert @worker . pool . shutdown?
101+
102+ wait_for_registered_processes ( 0 , timeout : 1 . second )
103+ assert_no_registered_processes
104+
105+ assert_equal 0 , SolidQueue ::ClaimedExecution . count
106+ assert SolidQueue ::Job . last . reload . ready?
107+ ensure
108+ SolidQueue . on_thread_error = previous_on_thread_error
109+ end
110+
111+ test "worker keeps running after a regular job failure" do
112+ RaisingJob . perform_later ( ExpectedTestError , "B" )
113+ AddToBufferJob . perform_later "ok"
114+
115+ @worker . start
116+
117+ wait_for_jobs_to_finish_for ( 2 . seconds )
118+ @worker . wake_up
119+
120+ assert_not @worker . pool . shutdown?
121+ assert_equal "ok" , JobBuffer . last_value
122+ assert_equal 0 , SolidQueue ::ClaimedExecution . count
123+ end
124+
88125 test "claim and process more enqueued jobs than the pool size allows to process at once" do
89126 5 . times do |i |
90127 StoreResultJob . perform_later ( :paused , pause : 0.1 . second )
0 commit comments