Skip to content

Commit 99737f3

Browse files
committed
Fix test connection handling
1 parent a810948 commit 99737f3

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
gemfile: [Gemfile, delayed.gemfile]
16-
ruby-version: ['3.0', '3.1', '3.2']
16+
ruby-version: ['3.2', '3.3', '3.4']
1717
env:
1818
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
1919
steps:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,5 @@ jobs.
179179
## License
180180

181181
Delayed::Cron::Job is released under the terms of the MIT License.
182-
Copyright 2014-2023 Pascal Zumkehr. See [LICENSE](LICENSE) for further
182+
Copyright 2014-2025 Pascal Zumkehr. See [LICENSE](LICENSE) for further
183183
information.

spec/delayed_cron_job_spec.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ class TestJob
66
def perform; end
77
end
88

9-
class DatabaseDisconnectPlugin < Delayed::Plugin
10-
11-
callbacks do |lifecycle|
12-
lifecycle.after(:perform) do
13-
ActiveRecord::Base.connection.disconnect!
14-
end
15-
end
16-
17-
end
18-
199
before { Delayed::Job.delete_all }
2010

2111
let(:cron) { '5 1 * * *' }
@@ -182,11 +172,25 @@ class DatabaseDisconnectPlugin < Delayed::Plugin
182172
end
183173

184174
context 'when database connection is lost' do
175+
176+
class DatabaseDisconnectPlugin < Delayed::Plugin
177+
callbacks do |lifecycle|
178+
lifecycle.after(:perform) do
179+
180+
pp ActiveRecord::Base.connection_pool.connections
181+
ActiveRecord::Base.connection.disconnect!
182+
end
183+
end
184+
end
185+
185186
around(:each) do |example|
186187
Delayed::Worker.plugins.unshift DatabaseDisconnectPlugin
187188
# hold onto a connection so the in-memory database isn't lost when disconnected
188189
temp_connection = ActiveRecord::Base.connection_pool.checkout
190+
temp_connection.connect!
191+
189192
example.run
193+
190194
ActiveRecord::Base.connection_pool.checkin temp_connection
191195
Delayed::Worker.plugins.delete DatabaseDisconnectPlugin
192196
end

0 commit comments

Comments
 (0)