Ensure we clean up state in PostgreSQL failover specs.
This commit is contained in:
parent
a173511681
commit
94782152c6
|
@ -89,23 +89,25 @@ describe ActiveRecord::ConnectionHandling do
|
||||||
expect(Sidekiq.paused?).to eq(true)
|
expect(Sidekiq.paused?).to eq(true)
|
||||||
|
|
||||||
with_multisite_db(multisite_db) do
|
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) }
|
expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
|
||||||
.to raise_error(PG::ConnectionBad)
|
.to change { Discourse.readonly_mode? }.from(false).to(true)
|
||||||
end.first
|
|
||||||
|
|
||||||
expect(message.data[:db]).to eq(multisite_db)
|
expect(postgresql_fallback_handler.master_down?).to eq(true)
|
||||||
|
ensure
|
||||||
expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
|
postgresql_fallback_handler.master_up(multisite_db)
|
||||||
.to change { Discourse.readonly_mode? }.from(false).to(true)
|
end
|
||||||
|
|
||||||
expect(postgresql_fallback_handler.master_down?).to eq(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
postgresql_fallback_handler.master_up(multisite_db)
|
|
||||||
|
|
||||||
ActiveRecord::Base.unstub(:postgresql_connection)
|
ActiveRecord::Base.unstub(:postgresql_connection)
|
||||||
|
|
||||||
postgresql_fallback_handler.initiate_fallback_to_master
|
postgresql_fallback_handler.initiate_fallback_to_master
|
||||||
|
|
Loading…
Reference in New Issue