Skip to content

Commit 5b80074

Browse files
committed
Use separate DB in tests and remove separate connection option
Since we'll use separate DBs for test, there's no need to run all tests with a separate connection.
1 parent f9b1db7 commit 5b80074

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

.github/workflows/main.yml

-2
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,3 @@ jobs:
5353
bin/rails db:setup
5454
- name: Run tests
5555
run: bin/rails test
56-
- name: Run tests with separate connection
57-
run: SEPARATE_CONNECTION=1 bin/rails test

test/dummy/config/application.rb

-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,5 @@ class Application < Rails::Application
2828
# config.eager_load_paths << Rails.root.join("extras")
2929

3030
config.active_job.queue_adapter = :solid_queue
31-
32-
if ENV["SEPARATE_CONNECTION"] && ENV["TARGET_DB"] != "sqlite"
33-
config.solid_queue.connects_to = { database: { writing: :primary, reading: :replica } }
34-
end
3531
end
3632
end

test/dummy/config/environments/test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
# Raises error for missing translations.
4848
# config.i18n.raise_on_missing_translations = true
4949

50+
# Replace the default in-process and non-durable queuing backend for Active Job.
51+
config.active_job.queue_adapter = :solid_queue
52+
config.solid_queue.connects_to = { database: { writing: :queue } }
53+
5054
# Annotate rendered view with file names.
5155
# config.action_view.annotate_rendered_view_with_filenames = true
5256

test/models/solid_queue/job_test.rb

+10-12
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,19 @@ class NonOverlappingGroupedJob2 < NonOverlappingJob
249249
end
250250
end
251251

252-
if ENV["SEPARATE_CONNECTION"] && ENV["TARGET_DB"] != "sqlite"
253-
test "uses a different connection and transaction than the one in use when connects_to is specified" do
254-
assert_difference -> { SolidQueue::Job.count } do
255-
assert_no_difference -> { JobResult.count } do
256-
JobResult.transaction do
257-
JobResult.create!(queue_name: "default", value: "this will be rolled back")
258-
StoreResultJob.perform_later("enqueued inside a rolled back transaction")
259-
raise ActiveRecord::Rollback
260-
end
252+
test "enqueue successfully inside a rolled-back transaction in the app DB" do
253+
assert_difference -> { SolidQueue::Job.count } do
254+
assert_no_difference -> { JobResult.count } do
255+
JobResult.transaction do
256+
JobResult.create!(queue_name: "default", value: "this will be rolled back")
257+
StoreResultJob.perform_later("enqueued inside a rolled back transaction")
258+
raise ActiveRecord::Rollback
261259
end
262260
end
263-
264-
job = SolidQueue::Job.last
265-
assert_equal "enqueued inside a rolled back transaction", job.arguments.dig("arguments", 0)
266261
end
262+
263+
job = SolidQueue::Job.last
264+
assert_equal "enqueued inside a rolled back transaction", job.arguments.dig("arguments", 0)
267265
end
268266

269267
private

0 commit comments

Comments
 (0)