DEV: Better clean up for PostgreSQL failover test.

This commit is contained in:
Guo Xiang Tan 2018-07-10 09:53:25 +08:00
parent 5374a0e720
commit 4163f9e61e
2 changed files with 6 additions and 1 deletions

View File

@ -7,6 +7,7 @@ class SidekiqPauser
def pause!
redis.setex paused_key, 60, "paused"
@mutex.synchronize do
@extend_lease_thread ||= extend_lease_thread
sleep 0.001 while !paused?
@ -35,7 +36,7 @@ class SidekiqPauser
while true do
break unless @mutex.synchronize { @extend_lease_thread }
redis.expire paused_key, 60
sleep 30
sleep(Rails.env.test? ? 0.01 : 30)
end
end
end

View File

@ -27,6 +27,7 @@ describe ActiveRecord::ConnectionHandling do
let(:postgresql_fallback_handler) { PostgreSQLFallbackHandler.instance }
before do
@threads = Thread.list
postgresql_fallback_handler.initialized = true
['default', multisite_db].each do |db|
@ -35,10 +36,13 @@ describe ActiveRecord::ConnectionHandling do
end
after do
Sidekiq.unpause!
postgresql_fallback_handler.setup!
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
ActiveRecord::Base.unstub(:postgresql_connection)
ActiveRecord::Base.establish_connection
(Thread.list - @threads).each(&:join)
end
describe "#postgresql_fallback_connection" do