Skip to content

Commit 3c81ed7

Browse files
nerdrewetagwerker
authored andcommitted
release_connection after cleaning (#122)
For Rails >= 7.2, this library gets a connection via `#lease_connection`. But it never releases the connection. Release the connection back to the pool after `#clean`-ing. Rails >= 7.2 does connection health checks / reconnect on connection checkout. If the connection is never checked back into the pool, it will never get "repaired", which makes testing database connection issues tricky.
1 parent 8c972ee commit 3c81ed7

File tree

12 files changed

+54
-7
lines changed

12 files changed

+54
-7
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,47 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
ruby: ['3.3', '3.2', '3.1']
13-
rails: ['6.1', '7.0', '7.1', '7.2']
12+
ruby: ['3.4', '3.3', '3.2', '3.1']
13+
rails: ['6.1', '7.0', '7.1', '7.2', '8.0']
1414
channel: ['stable']
1515

1616
include:
1717
- ruby: 'ruby-head'
1818
rails: 'edge'
1919
channel: 'experimental'
20+
- ruby: 'ruby-head'
21+
rails: '8.0'
22+
channel: 'experimental'
2023
- ruby: 'ruby-head'
2124
rails: '7.2'
2225
channel: 'experimental'
2326
- ruby: 'ruby-head'
2427
rails: '7.1'
2528
channel: 'experimental'
2629

27-
- ruby: '3.3'
30+
- ruby: '3.4'
2831
rails: 'edge'
2932
channel: 'experimental'
30-
- ruby: '3.2'
33+
- ruby: '3.3'
3134
rails: 'edge'
3235
channel: 'experimental'
33-
- ruby: '3.1'
36+
- ruby: '3.2'
3437
rails: 'edge'
3538
channel: 'experimental'
3639

3740
exclude:
38-
- ruby: '3.3'
39-
rails: '7.0' # TODO: works on 7-0-stable branch, remove after a 7.0.x patch release
41+
- ruby: '3.4'
42+
rails: '6.1'
43+
4044
- ruby: '3.3'
4145
rails: '6.1'
4246

4347
- ruby: '3.2'
4448
rails: '6.1'
4549

50+
- ruby: '3.1'
51+
rails: '8.0'
52+
4653
continue-on-error: ${{ matrix.channel != 'stable' }}
4754

4855
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Development (unreleased)
22

3+
* Release database connections after cleaning: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/122
34
* Provide a 'Changelog' link on Rubygems: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/114
45
* Fix bundling and CONTRIBUTE.md instructions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/123
56
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker

gemfiles/rails_6.1.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_c
66
gem "rails", "~> 6.1.0"
77
gem "sqlite3", "~> 1.5"
88
gem "concurrent-ruby", "1.3.4"
9+
gem "logger"
10+
gem "mutex_m"
11+
gem "bigdecimal"
912

1013
group :test do
1114
gem "simplecov", require: false

gemfiles/rails_7.0.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_c
66
gem "rails", "~> 7.0.0"
77
gem "sqlite3", "~> 1.7"
88
gem "concurrent-ruby", "1.3.4"
9+
gem "logger"
10+
gem "mutex_m"
11+
gem "bigdecimal"
912

1013
group :test do
1114
gem "simplecov", require: false

gemfiles/rails_7.1.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ source "https://rubygems.org"
55
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
66
gem "rails", "~> 7.1.0"
77
gem "sqlite3", "~> 1.7"
8+
gem "logger"
9+
gem "mutex_m"
10+
gem "bigdecimal"
811

912
group :test do
1013
gem "simplecov", require: false

gemfiles/rails_7.2.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ source "https://rubygems.org"
44

55
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
66
gem "rails", "~> 7.2.0"
7+
gem "logger"
8+
gem "mutex_m"
9+
gem "bigdecimal"
710

811
group :test do
912
gem "simplecov", require: false

gemfiles/rails_8.0.gemfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
6+
gem "rails", "~> 8.0"
7+
gem "logger"
8+
gem "mutex_m"
9+
gem "bigdecimal"
10+
11+
group :test do
12+
gem "simplecov", require: false
13+
gem "codecov", require: false
14+
end
15+
16+
gemspec path: "../"

gemfiles/rails_edge.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ source "https://rubygems.org"
44

55
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
66
gem "rails", github: "rails/rails"
7+
gem "logger"
8+
gem "mutex_m"
9+
gem "bigdecimal"
710

811
group :test do
912
gem "simplecov", require: false

lib/database_cleaner/active_record/deletion.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def clean
99
delete_tables(connection, tables_to_clean(connection))
1010
end
1111
end
12+
13+
connection_class.connection_pool.release_connection
1214
end
1315

1416
private

lib/database_cleaner/active_record/transaction.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def clean
2222
connection.rollback_transaction
2323
end
2424
end
25+
26+
connection_class.connection_pool.release_connection
2527
end
2628
end
2729
end

0 commit comments

Comments
 (0)