mirror of
https://github.com/discourse/discourse.git
synced 2025-07-06 09:12:30 +00:00
Be more forceful in disconnecting connections during failover.
This commit is contained in:
parent
ad70502ab8
commit
08b268c5bc
@ -99,7 +99,7 @@ class PostgreSQLFallbackHandler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear_connections
|
def clear_connections
|
||||||
ActiveRecord::Base.connection_pool.disconnect
|
ActiveRecord::Base.connection_pool.disconnect!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -38,22 +38,18 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
after do
|
after do
|
||||||
Sidekiq.unpause!
|
Sidekiq.unpause!
|
||||||
postgresql_fallback_handler.setup!
|
postgresql_fallback_handler.setup!
|
||||||
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
|
||||||
ActiveRecord::Base.unstub(:postgresql_connection)
|
ActiveRecord::Base.unstub(:postgresql_connection)
|
||||||
(Thread.list - @threads).each(&:kill)
|
(Thread.list - @threads).each(&:kill)
|
||||||
|
ActiveRecord::Base.connection_pool.disconnect!
|
||||||
ActiveRecord::Base.establish_connection
|
ActiveRecord::Base.establish_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#postgresql_fallback_connection" do
|
describe "#postgresql_fallback_connection" do
|
||||||
it 'should return a PostgreSQL adapter' do
|
it 'should return a PostgreSQL adapter' do
|
||||||
begin
|
connection = ActiveRecord::Base.postgresql_fallback_connection(config)
|
||||||
connection = ActiveRecord::Base.postgresql_fallback_connection(config)
|
|
||||||
|
|
||||||
expect(connection)
|
expect(connection)
|
||||||
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
.to be_an_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
||||||
ensure
|
|
||||||
connection.disconnect!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when master server is down' do
|
context 'when master server is down' do
|
||||||
@ -127,8 +123,6 @@ describe ActiveRecord::ConnectionHandling do
|
|||||||
|
|
||||||
expect(Discourse.readonly_mode?).to eq(false)
|
expect(Discourse.readonly_mode?).to eq(false)
|
||||||
expect(Sidekiq.paused?).to eq(false)
|
expect(Sidekiq.paused?).to eq(false)
|
||||||
|
|
||||||
# fails sometimes on this line!
|
|
||||||
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)
|
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)
|
||||||
expect(postgresql_fallback_handler.master_down?).to eq(nil)
|
expect(postgresql_fallback_handler.master_down?).to eq(nil)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user