55if RAILS_VERSION >= 7.1 && RUBY_VERSION >= "3.1"
66 require "solid_queue"
77
8- RSpec . describe "Sentry + ActiveJob on SolidQueue" do
8+ RSpec . describe "Sentry + ActiveJob on SolidQueue" , type : :job do
99 include ActiveSupport ::Testing ::TimeHelpers
1010 include_context "active_job backend harness" , adapter : :solid_queue
1111
12+ # Instantiated once. Each SolidQueueAdapter.new registers a
13+ # SolidQueue.on_worker_stop callback at class-load time (mutating
14+ # global SolidQueue state), so creating a fresh adapter per example
15+ # would accumulate callbacks across the run.
16+ SOLID_QUEUE_ADAPTER_FOR_TEST = ::ActiveJob ::QueueAdapters ::SolidQueueAdapter . new
17+
18+ def queue_adapter_for_test
19+ SOLID_QUEUE_ADAPTER_FOR_TEST
20+ end
21+
1222 WORKER_SHARD_COUNT = 4
1323
1424 def boot_adapter ( _adapter )
@@ -86,9 +96,19 @@ def drain(at: nil)
8696 name : "spec-#{ SecureRandom . hex ( 4 ) } "
8797 )
8898
99+ # Loop until both ready and scheduled tables are empty so that
100+ # retry_on cascades cleanly: a failing perform pushes the job into
101+ # SolidQueue::ScheduledExecution (via enqueue_at), which the next
102+ # iteration promotes to ReadyExecution and claims for execution.
103+ # A single dispatch+claim pass would only observe the first
104+ # attempt.
89105 run = lambda do
90- SolidQueue ::ScheduledExecution . dispatch_next_batch ( 100 )
91- SolidQueue ::ReadyExecution . claim ( "*" , 100 , process . id ) . each ( &:perform )
106+ loop do
107+ SolidQueue ::ScheduledExecution . dispatch_next_batch ( 100 )
108+ ready = SolidQueue ::ReadyExecution . claim ( "*" , 100 , process . id )
109+ break if ready . empty? && SolidQueue ::ScheduledExecution . none?
110+ ready . each ( &:perform )
111+ end
92112 end
93113
94114 # Only wrap in travel_to when the caller explicitly asks for a future
@@ -97,6 +117,10 @@ def drain(at: nil)
97117 at ? travel_to ( at , &run ) : run . call
98118 end
99119
120+ def last_enqueued_payload
121+ SolidQueue ::Job . order ( :id ) . last &.arguments
122+ end
123+
100124 it_behaves_like "a Sentry-instrumented ActiveJob backend"
101125 it_behaves_like "an ActiveJob backend that supports distributed tracing"
102126 end
0 commit comments