Skip to content

Handle unresolved Sentinel master/replica error #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/redis_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _set_config(config)
end

def message
return super unless config
return super unless config&.resolved?

"#{super} (#{config.server_url})"
end
Expand Down
4 changes: 4 additions & 0 deletions lib/redis_client/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def username
@username || DEFAULT_USERNAME
end

def resolved?
true
end

def sentinel?
false
end
Expand Down
6 changes: 6 additions & 0 deletions lib/redis_client/sentinel_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def check_role!(role)
end
end

def resolved?
@mutex.synchronize do
!!@config
end
end

private

def sentinels_to_configs(sentinels)
Expand Down
16 changes: 16 additions & 0 deletions test/sentinel/sentinel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ def test_unknown_master
end
end

def test_unresolved_config
client = @config.new_client

@config.stub(:server_url, -> { raise ConnectionError.with_config('this should not be called', @config) }) do
@config.stub(:resolved?, false) do
client.stub(:call, ->(_) { raise ConnectionError.with_config('call error', @config) }) do
error = assert_raises ConnectionError do
client.call('PING')
end

assert_equal 'call error', error.message
end
end
end
end

def test_master_failover_not_ready
sentinel_client_mock = SentinelClientMock.new([
[["SENTINEL", "get-master-addr-by-name", "cache"], [Servers::REDIS_REPLICA.host, Servers::REDIS_REPLICA.port.to_s]],
Expand Down