Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
gemfile: rails_8_1
- ruby-version: "3.1"
gemfile: rails_main
- ruby-version: "3.2"
gemfile: rails_main
services:
mysql:
image: mysql:8.0.31
Expand Down
13 changes: 7 additions & 6 deletions test/dummy/config/initializers/sqlite3.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module SqliteImmediateTransactions
def begin_db_transaction
if Rails.gem_version < Gem::Version.new("8.2")
log("begin immediate transaction", "TRANSACTION") do
with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
conn.transaction(:immediate)
end
log("begin immediate transaction", "TRANSACTION") do
with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
conn.transaction(:immediate)
end
end
end
Expand All @@ -26,7 +24,10 @@ def configure_connection

ActiveSupport.on_load :active_record do
if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend SqliteImmediateTransactions
# Rails 8.0+ has immediate transactions built-in
if Rails::VERSION::MAJOR < 8
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend SqliteImmediateTransactions
end
ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend SQLite3Configuration
end

Expand Down
12 changes: 8 additions & 4 deletions test/integration/concurrency_controls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ class ConcurrencyControlsTest < ActiveSupport::TestCase
end

test "verify transactions remain valid after Job creation conflicts via limits_concurrency" do
# Doesn't work with enqueue_after_transaction_commit? true on SolidQueueAdapter, but only Rails 7.2 uses this
skip if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 2
# Doesn't work when enqueue_after_transaction_commit is enabled
skip if ActiveJob::Base.respond_to?(:enqueue_after_transaction_commit) &&
[ true, :default ].include?(ActiveJob::Base.enqueue_after_transaction_commit)

ActiveRecord::Base.transaction do
NonOverlappingUpdateResultJob.perform_later(@result, name: "A", pause: 0.2.seconds)
Expand All @@ -196,6 +197,8 @@ class ConcurrencyControlsTest < ActiveSupport::TestCase

test "discard jobs when concurrency limit is reached with on_conflict: :discard" do
job1 = DiscardableUpdateResultJob.perform_later(@result, name: "1", pause: 3)
sleep(0.1)

# should be discarded due to concurrency limit
job2 = DiscardableUpdateResultJob.perform_later(@result, name: "2")
# should also be discarded
Expand All @@ -218,8 +221,9 @@ class ConcurrencyControlsTest < ActiveSupport::TestCase

test "discard on conflict across different concurrency keys" do
another_result = JobResult.create!(queue_name: "default", status: "")
DiscardableUpdateResultJob.perform_later(@result, name: "1", pause: 0.2)
DiscardableUpdateResultJob.perform_later(another_result, name: "2", pause: 0.2)
DiscardableUpdateResultJob.perform_later(@result, name: "1", pause: 2)
DiscardableUpdateResultJob.perform_later(another_result, name: "2", pause: 2)
sleep(0.1)
DiscardableUpdateResultJob.perform_later(@result, name: "3") # Should be discarded
DiscardableUpdateResultJob.perform_later(another_result, name: "4") # Should be discarded

Expand Down
5 changes: 3 additions & 2 deletions test/models/solid_queue/job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ class DiscardableNonOverlappingGroupedJob2 < NonOverlappingJob
end

test "enqueue successfully inside a rolled-back transaction in the app DB" do
# Doesn't work with enqueue_after_transaction_commit? true on SolidQueueAdapter, but only Rails 7.2 uses this
skip if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 2
# Doesn't work when enqueue_after_transaction_commit is enabled
skip if ActiveJob::Base.respond_to?(:enqueue_after_transaction_commit) &&
[ true, :default ].include?(ActiveJob::Base.enqueue_after_transaction_commit)
assert_difference -> { SolidQueue::Job.count } do
assert_no_difference -> { JobResult.count } do
JobResult.transaction do
Expand Down