@@ -8,40 +8,51 @@ def setup
88 end
99
1010 def test_connect_and_manual_refresh_with_secondaries_down
11- @rs . secondaries . each { | s | s . stop }
11+ num_secondaries = @rs . secondaries . size
1212 client = MongoReplicaSetClient . new ( @rs . repl_set_seeds , :refresh_mode => false )
1313
14- assert_equal Set . new , client . secondaries
14+ assert_equal num_secondaries , client . secondaries . size
1515 assert client . connected?
1616 assert_equal client . read_pool , client . primary_pool
1717
18- # Refresh with no change to set
18+ @rs . secondaries . each { |s | s . stop }
19+
1920 client . refresh
20- assert_equal Set . new , client . secondaries
21+ assert client . secondaries . empty?
2122 assert client . connected?
2223 assert_equal client . read_pool , client . primary_pool
2324
2425 # Test no changes after restart until manual refresh
2526 @rs . restart
26- assert_equal Set . new , client . secondaries
27+ assert client . secondaries . empty?
2728 assert client . connected?
2829 assert_equal client . read_pool , client . primary_pool
2930
3031 # Refresh and ensure state
3132 client . refresh
3233 assert_equal client . read_pool , client . primary_pool
33- assert_equal 2 , client . secondaries . length
34+ assert_equal num_secondaries , client . secondaries . size
3435 end
3536
3637 def test_automated_refresh_with_secondaries_down
37- @rs . secondaries . each { | s | s . stop }
38+ num_secondaries = @rs . secondaries . size
3839 client = MongoReplicaSetClient . new ( @rs . repl_set_seeds ,
3940 :refresh_interval => 1 , :refresh_mode => :sync , :read => :secondary_preferred )
4041
4142 # 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?
4353 assert client . connected?
44- assert client . manager . pools . member? ( client . manager . read_pool )
54+ assert_equal client . read_pool , client . primary_pool
55+
4556 old_refresh_version = client . refresh_version
4657
4758 # Restart nodes and ensure refresh interval has passed
@@ -56,7 +67,7 @@ def test_automated_refresh_with_secondaries_down
5667
5768 assert client . refresh_version > old_refresh_version ,
5869 "Refresh version hasn't changed."
59- assert client . secondaries . length == 2 ,
70+ assert_equal num_secondaries , client . secondaries . size
6071 "No secondaries have been added."
6172 assert client . manager . read_pool != client . manager . primary ,
6273 "Read pool and primary pool are identical."
@@ -66,11 +77,11 @@ def test_automated_refresh_when_secondary_goes_down
6677 client = MongoReplicaSetClient . new ( @rs . repl_set_seeds ,
6778 :refresh_interval => 1 , :refresh_mode => :sync )
6879
69- num_secondaries = client . secondary_pools . length
80+ num_secondaries = client . secondary_pools . size
7081 old_refresh_version = client . refresh_version
7182
72- @rs . kill_secondary
73- sleep ( 1 )
83+ @rs . stop_secondary
84+ sleep ( 2 )
7485
7586 assert client . refresh_version == old_refresh_version ,
7687 "Refresh version has changed."
@@ -79,16 +90,16 @@ def test_automated_refresh_when_secondary_goes_down
7990
8091 assert client . refresh_version > old_refresh_version ,
8192 "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
8495
85- @rs . start
96+ @rs . restart
8697 sleep ( 2 )
8798
8899 client [ 'foo' ] [ 'bar' ] . find_one
89100
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
92103 end
93104=begin
94105 def test_automated_refresh_with_removed_node
0 commit comments