1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# frozen_string_literal: true
require "helper"
# @see https://redis.io/topics/sentinel#sentinel-commands Sentinel commands
class SentinelCommandsTest < Minitest::Test
include Helper::Sentinel
def test_sentinel_command_master
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('master', MASTER_NAME)
assert_equal result['name'], MASTER_NAME
assert_equal result['ip'], LOCALHOST
end
def test_sentinel_command_masters
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('masters')
assert_equal result[0]['name'], MASTER_NAME
assert_equal result[0]['ip'], LOCALHOST
assert_equal result[0]['port'], MASTER_PORT
end
def test_sentinel_command_slaves
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('slaves', MASTER_NAME)
assert_equal result[0]['name'], "#{LOCALHOST}:#{SLAVE_PORT}"
assert_equal result[0]['ip'], LOCALHOST
assert_equal result[0]['port'], SLAVE_PORT
end
def test_sentinel_command_sentinels
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('sentinels', MASTER_NAME)
assert_equal result[0]['ip'], LOCALHOST
actual_ports = result.map { |r| r['port'] }.sort
expected_ports = SENTINEL_PORTS[1..-1]
assert_equal actual_ports, expected_ports
end
def test_sentinel_command_get_master_by_name
redis = build_sentinel_client
result = redis.sentinel('get-master-addr-by-name', MASTER_NAME)
assert_equal result, [LOCALHOST, MASTER_PORT]
end
def test_sentinel_command_ckquorum
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('ckquorum', MASTER_NAME)
assert_equal result, 'OK 3 usable Sentinels. Quorum and failover authorization can be reached'
end
end
|