Skip to content

Commit b610cb2

Browse files
solnicclaude
andcommitted
refactor(rails): introduce worker_thread harness hook for the hub-isolation example
The worker_hub_isolation shared example previously hard-coded Thread.new for the two concurrent jobs it spawns. That works fine on adapters that keep their queue state in-process (:test, :inline) but some real adapters need per-thread setup (e.g. :solid_queue on SQLite needs an isolated database per worker thread to avoid SQLite3::BusyException). Adds a `worker_thread(&block)` hook on the harness, defaulting to `Thread.new(&block)`, and switches the shared example to call it. Adapters that need extra worker setup override the hook. Behaviour on :test (the only adapter on this branch) is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 529d724 commit b610cb2

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

sentry-rails/spec/active_job/shared_examples/tracing/worker_hub_isolation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def perform
2020

2121
Sentry.get_current_scope.set_tags(test_thread: true)
2222

23-
thread_a = Thread.new { job_a.perform_later; drain }
24-
thread_b = Thread.new { job_b.perform_later; drain }
23+
thread_a = worker_thread { job_a.perform_later; drain }
24+
thread_b = worker_thread { job_b.perform_later; drain }
2525
[thread_a, thread_b].each(&:join)
2626

2727
txn_a = transactions.find { |t| t.tags[:job] == "A" }

sentry-rails/spec/active_job/support/harness.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,12 @@ def within_parent_transaction(name: "parent.test", op: "test")
6969
ensure
7070
txn&.finish
7171
end
72+
73+
# Hook used by the worker_hub_isolation shared example. The default
74+
# is a plain Thread.new — adapters that need extra setup (e.g. an
75+
# isolated database per worker thread, like :solid_queue on SQLite)
76+
# override this to wrap the block in their isolation scope.
77+
def worker_thread(&block)
78+
Thread.new(&block)
79+
end
7280
end

0 commit comments

Comments
 (0)