@@ -7,20 +7,44 @@ class TestClusterClientOptions < Minitest::Test
7
7
include Helper ::Cluster
8
8
9
9
def test_option_class
10
- option = Redis ::Cluster ::Option . new ( cluster : %w[ rediss://127.0.0.1:7000 ] , replica : true )
11
- assert_equal ( { '127.0.0.1:7000' => { url : 'rediss://127.0.0.1:7000' } } , option . per_node_key )
12
- assert_equal true , option . secure?
10
+ option = Redis ::Cluster ::Option . new ( cluster : %w[ redis://127.0.0.1:7000 ] , replica : true )
11
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'redis' , host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
13
12
assert_equal true , option . use_replica?
14
13
15
14
option = Redis ::Cluster ::Option . new ( cluster : %w[ redis://127.0.0.1:7000 ] , replica : false )
16
- assert_equal ( { '127.0.0.1:7000' => { url : 'redis://127.0.0.1:7000' } } , option . per_node_key )
17
- assert_equal false , option . secure?
15
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'redis' , host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
18
16
assert_equal false , option . use_replica?
19
17
20
18
option = Redis ::Cluster ::Option . new ( cluster : %w[ redis://127.0.0.1:7000 ] )
21
- assert_equal ( { '127.0.0.1:7000' => { url : 'redis://127.0.0.1:7000' } } , option . per_node_key )
22
- assert_equal false , option . secure?
19
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'redis' , host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
23
20
assert_equal false , option . use_replica?
21
+
22
+ option = Redis ::
Cluster ::
Option . new ( cluster :
%w[ rediss://johndoe:[email protected] :7000/1/namespace ] )
23
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'rediss' , password : 'foobar' , host : '127.0.0.1' , port : 7000 , db : 1 } } , option . per_node_key )
24
+
25
+ option = Redis ::Cluster ::Option . new ( cluster : %w[ rediss://127.0.0.1:7000 ] , scheme : 'redis' )
26
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'rediss' , host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
27
+
28
+ option = Redis ::
Cluster ::
Option . new ( cluster :
%w[ redis://:[email protected] :7000 ] , password :
'foobar' )
29
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'redis' , password : 'bazzap' , host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
30
+
31
+ option = Redis ::Cluster ::Option . new ( cluster : %w[ redis://127.0.0.1:7000/0 ] , db : 1 )
32
+ assert_equal ( { '127.0.0.1:7000' => { scheme : 'redis' , host : '127.0.0.1' , port : 7000 , db : 0 } } , option . per_node_key )
33
+
34
+ option = Redis ::Cluster ::Option . new ( cluster : [ { host : '127.0.0.1' , port : 7000 } ] )
35
+ assert_equal ( { '127.0.0.1:7000' => { host : '127.0.0.1' , port : 7000 } } , option . per_node_key )
36
+
37
+ assert_raises ( Redis ::InvalidClientOptionError ) do
38
+ Redis ::Cluster ::Option . new ( cluster : nil )
39
+ end
40
+
41
+ assert_raises ( Redis ::InvalidClientOptionError ) do
42
+ Redis ::Cluster ::Option . new ( cluster : %w[ invalid_uri ] )
43
+ end
44
+
45
+ assert_raises ( Redis ::InvalidClientOptionError ) do
46
+ Redis ::Cluster ::Option . new ( cluster : [ { host : '127.0.0.1' } ] )
47
+ end
24
48
end
25
49
26
50
def test_client_accepts_valid_node_configs
@@ -43,7 +67,9 @@ def test_client_ignores_invalid_options
43
67
end
44
68
45
69
def test_client_works_even_if_so_many_unavailable_nodes_specified
46
- nodes = ( 6001 ..7005 ) . map { |port | "redis://127.0.0.1:#{ port } " }
70
+ min = 7000
71
+ max = min + Process . getrlimit ( Process ::RLIMIT_NOFILE ) . first / 3 * 2
72
+ nodes = ( min ..max ) . map { |port | "redis://127.0.0.1:#{ port } " }
47
73
redis = build_another_client ( cluster : nodes )
48
74
49
75
assert_equal 'PONG' , redis . ping
0 commit comments