FIX: Don't treat master as up if it is still loading data.

This commit is contained in:
Guo Xiang Tan 2016-11-07 15:28:10 +08:00
parent 9375dcb6fe
commit fbbcde1230
2 changed files with 14 additions and 2 deletions

View File

@ -98,8 +98,8 @@ class DiscourseRedis
options = @options.dup
options.delete(:connector)
client = Redis::Client.new(options)
client.call([:role])
@options
loading = client.call([:info]).split("\r\n").include?("loading:1")
loading ? @slave_options : @options
rescue Redis::ConnectionError, Redis::CannotConnectError, RuntimeError => ex
raise ex if ex.class == RuntimeError && ex.message != "Name or service not known"
@fallback_handler.master = false

View File

@ -70,6 +70,18 @@ describe DiscourseRedis do
end
end
it "should return the slave config when master is still loading data" do
begin
Redis::Client.any_instance.expects(:call).with([:info]).returns("someconfig:haha\r\nloading:1")
config = connector.resolve
expect(config[:host]).to eq(slave_host)
expect(config[:port]).to eq(slave_port)
ensure
fallback_handler.master = true
end
end
it "should raise the right error" do
error = RuntimeError.new('test error')
Redis::Client.any_instance.expects(:call).raises(error).twice