@@ -8,40 +8,51 @@ def setup
8
8
end
9
9
10
10
def test_connect_and_manual_refresh_with_secondaries_down
11
- @rs . secondaries . each { | s | s . stop }
11
+ num_secondaries = @rs . secondaries . size
12
12
client = MongoReplicaSetClient . new ( @rs . repl_set_seeds , :refresh_mode => false )
13
13
14
- assert_equal Set . new , client . secondaries
14
+ assert_equal num_secondaries , client . secondaries . size
15
15
assert client . connected?
16
16
assert_equal client . read_pool , client . primary_pool
17
17
18
- # Refresh with no change to set
18
+ @rs . secondaries . each { |s | s . stop }
19
+
19
20
client . refresh
20
- assert_equal Set . new , client . secondaries
21
+ assert client . secondaries . empty?
21
22
assert client . connected?
22
23
assert_equal client . read_pool , client . primary_pool
23
24
24
25
# Test no changes after restart until manual refresh
25
26
@rs . restart
26
- assert_equal Set . new , client . secondaries
27
+ assert client . secondaries . empty?
27
28
assert client . connected?
28
29
assert_equal client . read_pool , client . primary_pool
29
30
30
31
# Refresh and ensure state
31
32
client . refresh
32
33
assert_equal client . read_pool , client . primary_pool
33
- assert_equal 2 , client . secondaries . length
34
+ assert_equal num_secondaries , client . secondaries . size
34
35
end
35
36
36
37
def test_automated_refresh_with_secondaries_down
37
- @rs . secondaries . each { | s | s . stop }
38
+ num_secondaries = @rs . secondaries . size
38
39
client = MongoReplicaSetClient . new ( @rs . repl_set_seeds ,
39
40
:refresh_interval => 1 , :refresh_mode => :sync , :read => :secondary_preferred )
40
41
41
42
# Ensure secondaries not available and read from primary
42
- assert_equal Set . new , client . secondaries
43
+ assert_equal num_secondaries , client . secondaries . size
44
+ assert client . connected?
45
+ assert client . secondary_pools . include? ( client . read_pool )
46
+
47
+ @rs . secondaries . each { |s | s . stop }
48
+ sleep ( 2 )
49
+
50
+ client [ 'foo' ] [ 'bar' ] . find_one
51
+
52
+ assert client . secondaries . empty?
43
53
assert client . connected?
44
- assert client . manager . pools . member? ( client . manager . read_pool )
54
+ assert_equal client . read_pool , client . primary_pool
55
+
45
56
old_refresh_version = client . refresh_version
46
57
47
58
# Restart nodes and ensure refresh interval has passed
@@ -56,7 +67,7 @@ def test_automated_refresh_with_secondaries_down
56
67
57
68
assert client . refresh_version > old_refresh_version ,
58
69
"Refresh version hasn't changed."
59
- assert client . secondaries . length == 2 ,
70
+ assert_equal num_secondaries , client . secondaries . size
60
71
"No secondaries have been added."
61
72
assert client . manager . read_pool != client . manager . primary ,
62
73
"Read pool and primary pool are identical."
@@ -66,11 +77,11 @@ def test_automated_refresh_when_secondary_goes_down
66
77
client = MongoReplicaSetClient . new ( @rs . repl_set_seeds ,
67
78
:refresh_interval => 1 , :refresh_mode => :sync )
68
79
69
- num_secondaries = client . secondary_pools . length
80
+ num_secondaries = client . secondary_pools . size
70
81
old_refresh_version = client . refresh_version
71
82
72
- @rs . kill_secondary
73
- sleep ( 1 )
83
+ @rs . stop_secondary
84
+ sleep ( 2 )
74
85
75
86
assert client . refresh_version == old_refresh_version ,
76
87
"Refresh version has changed."
@@ -79,16 +90,16 @@ def test_automated_refresh_when_secondary_goes_down
79
90
80
91
assert client . refresh_version > old_refresh_version ,
81
92
"Refresh version hasn't changed."
82
- assert_equal num_secondaries - 1 , client . secondaries . length
83
- assert_equal num_secondaries - 1 , client . secondary_pools . length
93
+ assert_equal num_secondaries - 1 , client . secondaries . size
94
+ assert_equal num_secondaries - 1 , client . secondary_pools . size
84
95
85
- @rs . start
96
+ @rs . restart
86
97
sleep ( 2 )
87
98
88
99
client [ 'foo' ] [ 'bar' ] . find_one
89
100
90
- assert_equal num_secondaries , client . secondaries . length
91
- assert_equal num_secondaries , client . secondary_pools . length
101
+ assert_equal num_secondaries , client . secondaries . size
102
+ assert_equal num_secondaries , client . secondary_pools . size
92
103
end
93
104
=begin
94
105
def test_automated_refresh_with_removed_node
0 commit comments