RUBY-403 added test and fix for refresh health check attempting to close socket that may be nil
This commit is contained in:
parent
309315e31e
commit
07375ce024
|
@ -101,7 +101,12 @@ module Mongo
|
||||||
rescue ConnectionFailure, OperationFailure, OperationTimeout, SocketError, SystemCallError, IOError => ex
|
rescue ConnectionFailure, OperationFailure, OperationTimeout, SocketError, SystemCallError, IOError => ex
|
||||||
@connection.log(:warn, "Attempted connection to node #{host_string} raised " +
|
@connection.log(:warn, "Attempted connection to node #{host_string} raised " +
|
||||||
"#{ex.class}: #{ex.message}")
|
"#{ex.class}: #{ex.message}")
|
||||||
@socket.close unless @socket.closed?
|
|
||||||
|
# Socket may already be nil from issuing command
|
||||||
|
if @socket && !@socket.closed?
|
||||||
|
@socket.close
|
||||||
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,28 @@ class ReplicaSetRefreshTest < Test::Unit::TestCase
|
||||||
"Read pool and primary pool are identical."
|
"Read pool and primary pool are identical."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_automated_refresh_when_secondary_goes_down
|
||||||
|
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
|
||||||
|
[self.rs.host, self.rs.ports[1]],
|
||||||
|
[self.rs.host, self.rs.ports[2]],
|
||||||
|
:refresh_interval => 2,
|
||||||
|
:refresh_mode => :sync)
|
||||||
|
|
||||||
|
num_secondaries = @conn.secondary_pools.length
|
||||||
|
old_refresh_version = @conn.refresh_version
|
||||||
|
|
||||||
|
n = self.rs.kill_secondary
|
||||||
|
sleep(4)
|
||||||
|
@conn['foo']['bar'].find_one
|
||||||
|
|
||||||
|
assert @conn.refresh_version > old_refresh_version,
|
||||||
|
"Refresh version hasn't changed."
|
||||||
|
assert_equal num_secondaries - 1, @conn.secondaries.length
|
||||||
|
assert_equal num_secondaries - 1, @conn.secondary_pools.length
|
||||||
|
|
||||||
|
self.rs.restart_killed_nodes
|
||||||
|
end
|
||||||
|
|
||||||
def test_automated_refresh_with_removed_node
|
def test_automated_refresh_with_removed_node
|
||||||
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
|
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
|
||||||
[self.rs.host, self.rs.ports[1]],
|
[self.rs.host, self.rs.ports[1]],
|
||||||
|
|
Loading…
Reference in New Issue