Skip to content

Commit

Permalink
Use separate DB in tests and remove separate connection option
Browse files Browse the repository at this point in the history
Since we'll use separate DBs for test, there's no need to run all tests
with a separate connection.
  • Loading branch information
rosa committed Nov 13, 2024
1 parent e8b6384 commit b515af2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ jobs:
bin/rails db:setup
- name: Run tests
run: bin/rails test
- name: Run tests with separate connection
run: SEPARATE_CONNECTION=1 bin/rails test
4 changes: 0 additions & 4 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@ class Application < Rails::Application
# config.eager_load_paths << Rails.root.join("extras")

config.active_job.queue_adapter = :solid_queue

if ENV["SEPARATE_CONNECTION"] && ENV["TARGET_DB"] != "sqlite"
config.solid_queue.connects_to = { database: { writing: :primary, reading: :replica } }
end
end
end
4 changes: 4 additions & 0 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

# Replace the default in-process and non-durable queuing backend for Active Job.
config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = { database: { writing: :queue } }

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

Expand Down
22 changes: 10 additions & 12 deletions test/models/solid_queue/job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,19 @@ class NonOverlappingGroupedJob2 < NonOverlappingJob
end
end

if ENV["SEPARATE_CONNECTION"] && ENV["TARGET_DB"] != "sqlite"
test "uses a different connection and transaction than the one in use when connects_to is specified" do
assert_difference -> { SolidQueue::Job.count } do
assert_no_difference -> { JobResult.count } do
JobResult.transaction do
JobResult.create!(queue_name: "default", value: "this will be rolled back")
StoreResultJob.perform_later("enqueued inside a rolled back transaction")
raise ActiveRecord::Rollback
end
test "enqueue successfully inside a rolled-back transaction in the app DB" do
assert_difference -> { SolidQueue::Job.count } do
assert_no_difference -> { JobResult.count } do
JobResult.transaction do
JobResult.create!(queue_name: "default", value: "this will be rolled back")
StoreResultJob.perform_later("enqueued inside a rolled back transaction")
raise ActiveRecord::Rollback
end
end

job = SolidQueue::Job.last
assert_equal "enqueued inside a rolled back transaction", job.arguments.dig("arguments", 0)
end

job = SolidQueue::Job.last
assert_equal "enqueued inside a rolled back transaction", job.arguments.dig("arguments", 0)
end

private
Expand Down

0 comments on commit b515af2

Please sign in to comment.