mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
clearing active connections in the ConnectionManagement middleware if an exception happens
This commit is contained in:
parent
e5246092d1
commit
3b2a032677
2 changed files with 10 additions and 0 deletions
|
@ -446,6 +446,9 @@ module ActiveRecord
|
|||
status, headers, body = @app.call(env)
|
||||
|
||||
[status, headers, Proxy.new(body, env.key?('rack.test'))]
|
||||
rescue
|
||||
ActiveRecord::Base.clear_active_connections!
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,6 +57,13 @@ module ActiveRecord
|
|||
assert ActiveRecord::Base.connection_handler.active_connections?
|
||||
end
|
||||
|
||||
def test_connections_closed_if_exception
|
||||
app = Class.new(App) { def call(env); raise; end }.new
|
||||
explosive = ConnectionManagement.new(app)
|
||||
assert_raises(RuntimeError) { explosive.call(@env) }
|
||||
assert !ActiveRecord::Base.connection_handler.active_connections?
|
||||
end
|
||||
|
||||
test "doesn't clear active connections when running in a test case" do
|
||||
@env['rack.test'] = true
|
||||
@management.call(@env)
|
||||
|
|
Loading…
Reference in a new issue