mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 16:51:25 +08:00
Fix broken condition in PostgresqlFallbackAdapter.
This commit is contained in:
@ -119,7 +119,14 @@ module ActiveRecord
|
|||||||
|
|
||||||
def verify_replica(connection)
|
def verify_replica(connection)
|
||||||
value = connection.raw_connection.exec("SELECT pg_is_in_recovery()").values[0][0]
|
value = connection.raw_connection.exec("SELECT pg_is_in_recovery()").values[0][0]
|
||||||
raise "Replica database server is not in recovery mode." if value == 'f'
|
|
||||||
|
if !value
|
||||||
|
begin
|
||||||
|
raise "Replica database server is not in recovery mode."
|
||||||
|
ensure
|
||||||
|
connection.close
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -96,8 +96,15 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
|
|
||||||
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)
|
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)
|
||||||
|
|
||||||
expect(ActiveRecord::Base.connection)
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
||||||
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
connection = ActiveRecord::Base.connection
|
||||||
|
|
||||||
|
begin
|
||||||
|
expect(connection)
|
||||||
|
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
||||||
|
ensure
|
||||||
|
connection.close
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,6 +122,16 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.verify_replica' do
|
||||||
|
describe 'when database is not in recovery' do
|
||||||
|
it 'should raise the right error' do
|
||||||
|
expect do
|
||||||
|
ActiveRecord::Base.send(:verify_replica, ActiveRecord::Base.connection)
|
||||||
|
end.to raise_error(RuntimeError, "Replica database server is not in recovery mode.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def with_multisite_db(dbname)
|
def with_multisite_db(dbname)
|
||||||
RailsMultisite::ConnectionManagement.expects(:current_db).returns(dbname).at_least_once
|
RailsMultisite::ConnectionManagement.expects(:current_db).returns(dbname).at_least_once
|
||||||
yield
|
yield
|
||||||
|
Reference in New Issue
Block a user