Skip to content

Commit

Permalink
Fix error in updated clear_all_connections handling
Browse files Browse the repository at this point in the history
  • Loading branch information
albus522 committed Aug 19, 2024
1 parent 1689f9d commit bb7db6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/delayed/backend/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def self.ready_to_run(worker_name, max_run_time)

def self.before_fork
if Gem::Version.new("7.1.0") <= Gem::Version.new(::ActiveRecord::VERSION::STRING)
::ActiveRecord::Base.clear_all_connections!(:all)
::ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
else
::ActiveRecord::Base.clear_all_connections!
::ActiveRecord::Base.connection_handler.clear_all_connections!
end
end

Expand Down
13 changes: 13 additions & 0 deletions spec/delayed/backend/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ def use_default_timezone(timezone)
end
end

describe "before_fork" do
it "clears all connections connection" do
allow(ActiveRecord::Base.connection_handler).to receive(:clear_all_connections!)
Delayed::Backend::ActiveRecord::Job.before_fork

if Gem::Version.new("7.1.0") <= Gem::Version.new(ActiveRecord::VERSION::STRING)
expect(ActiveRecord::Base.connection_handler).to have_received(:clear_all_connections!).with(:all)
else
expect(ActiveRecord::Base.connection_handler).to have_received(:clear_all_connections!)
end
end
end

describe "after_fork" do
it "calls reconnect on the connection" do
allow(ActiveRecord::Base).to receive(:establish_connection)
Expand Down

0 comments on commit bb7db6c

Please sign in to comment.