From 94782152c6ac0258b7903d5045053d5fe33de0b3 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 26 Oct 2017 09:22:24 +0800 Subject: [PATCH] Ensure we clean up state in PostgreSQL failover specs. --- .../postgresql_fallback_adapter_spec.rb | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb b/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb index c377a0d7981..ac8475d22e3 100644 --- a/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb +++ b/spec/components/active_record/connection_adapters/postgresql_fallback_adapter_spec.rb @@ -89,23 +89,25 @@ describe ActiveRecord::ConnectionHandling do expect(Sidekiq.paused?).to eq(true) with_multisite_db(multisite_db) do - expect(postgresql_fallback_handler.master_down?).to eq(nil) + begin + expect(postgresql_fallback_handler.master_down?).to eq(nil) + + message = MessageBus.track_publish(PostgreSQLFallbackHandler::DATABASE_DOWN_CHANNEL) do + expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) } + .to raise_error(PG::ConnectionBad) + end.first + + expect(message.data[:db]).to eq(multisite_db) - message = MessageBus.track_publish(PostgreSQLFallbackHandler::DATABASE_DOWN_CHANNEL) do expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) } - .to raise_error(PG::ConnectionBad) - end.first + .to change { Discourse.readonly_mode? }.from(false).to(true) - expect(message.data[:db]).to eq(multisite_db) - - expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) } - .to change { Discourse.readonly_mode? }.from(false).to(true) - - expect(postgresql_fallback_handler.master_down?).to eq(true) + expect(postgresql_fallback_handler.master_down?).to eq(true) + ensure + postgresql_fallback_handler.master_up(multisite_db) + end end - postgresql_fallback_handler.master_up(multisite_db) - ActiveRecord::Base.unstub(:postgresql_connection) postgresql_fallback_handler.initiate_fallback_to_master