Skip to content

Commit

Permalink
Fix and extend tests for slot
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul342 committed Mar 22, 2020
1 parent 1a188d6 commit af6f8bb
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions test/cluster_client_slots_test.rb
Expand Up @@ -7,7 +7,7 @@ class TestClusterClientSlots < Minitest::Test
include Helper::Cluster

def test_slot_class
slot = Redis::Cluster::Slot.new('127.0.0.1:7000' => 1..10)
slot = Redis::Cluster::Slot.new('127.0.0.1:7000' => [1..10])

assert_equal false, slot.exists?(0)
assert_equal true, slot.exists?(1)
Expand All @@ -26,8 +26,36 @@ def test_slot_class
assert_nil slot.put(1, '127.0.0.1:7001')
end

def test_slot_class_with_multiple_slot_ranges
slot = Redis::Cluster::Slot.new('127.0.0.1:7000' => [1..10, 30..40])

assert_equal false, slot.exists?(0)
assert_equal true, slot.exists?(1)
assert_equal true, slot.exists?(10)
assert_equal false, slot.exists?(11)
assert_equal true, slot.exists?(30)
assert_equal true, slot.exists?(40)
assert_equal false, slot.exists?(41)

assert_nil slot.find_node_key_of_master(0)
assert_nil slot.find_node_key_of_slave(0)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(1)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(1)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(10)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(10)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(30)
assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(40)
assert_nil slot.find_node_key_of_master(11)
assert_nil slot.find_node_key_of_slave(11)
assert_nil slot.find_node_key_of_master(41)
assert_nil slot.find_node_key_of_slave(41)

assert_nil slot.put(1, '127.0.0.1:7001')
assert_nil slot.put(30, '127.0.0.1:7001')
end

def test_slot_class_with_node_flags_and_replicas
slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => 1..10, '127.0.0.1:7001' => 1..10 },
slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => [1..10], '127.0.0.1:7001' => [1..10] },
{ '127.0.0.1:7000' => 'master', '127.0.0.1:7001' => 'slave' },
true)

Expand All @@ -49,7 +77,7 @@ def test_slot_class_with_node_flags_and_replicas
end

def test_slot_class_with_node_flags_and_without_replicas
slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => 1..10, '127.0.0.1:7001' => 1..10 },
slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => [1..10], '127.0.0.1:7001' => [1..10] },
{ '127.0.0.1:7000' => 'master', '127.0.0.1:7001' => 'slave' },
false)

Expand Down

0 comments on commit af6f8bb

Please sign in to comment.