RUBY-314 test for update when a node is removed

This commit is contained in:
Kyle Banker 2011-08-25 18:52:20 -04:00
parent 1c430abd88
commit 5559f91da2
4 changed files with 41 additions and 4 deletions

View File

@ -67,6 +67,10 @@ module Mongo
"#{@host}:#{@port}" "#{@host}:#{@port}"
end end
def host_port
[@host, @port]
end
# Return the time it takes on average # Return the time it takes on average
# to do a round-trip against this node. # to do a round-trip against this node.
def ping_time def ping_time

View File

@ -61,10 +61,9 @@ module Mongo
@primary = nil @primary = nil
@primary_pool.close @primary_pool.close
@primary_pool = nil @primary_pool = nil
elsif rejected_pool = @secondary_pools.reject! {|pool| pool.host_string == node} elsif rejected_pool = @secondary_pools.detect {|pool| pool.host_string == node}
@secondaries.reject! do |secondary| @secondary_pools.delete(rejected_pool)
secondary.port == rejected_pool.port && secondary.host == rejected_pool.host @secondaries.delete(rejected_pool.host_port)
end
end end
end end
end end

View File

@ -62,6 +62,19 @@ class ReplicaSetRefreshTest < Test::Unit::TestCase
end end
def test_automated_refresh_with_removed_node def test_automated_refresh_with_removed_node
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
[RS.host, RS.ports[2]], :refresh_interval => 2, :auto_refresh => true)
assert @conn.secondaries.length == 2
p @conn.secondaries
p @conn.secondary_pools.length
RS.remove_secondary_node
sleep(6)
p @conn.secondaries
p @conn.secondary_pools.length
assert @conn.secondaries.length == 1
end end
end end

View File

@ -103,6 +103,27 @@ class ReplSetManager
@mongods[n]['start'] @mongods[n]['start']
end end
def remove_secondary_node
primary = get_node_with_state(1)
con = get_connection(primary)
config = con['local']['system.replset'].find_one
secondary = get_node_with_state(2)
host_port = "#{@host}:#{@mongods[secondary]['port']}"
@config['members'].reject! {|m| m['host'] == host_port}
@config['version'] = config['version'] + 1
primary = get_node_with_state(1)
con = get_connection(primary)
begin
con['admin'].command({'replSetReconfig' => @config})
rescue Mongo::ConnectionFailure
end
con.close
end
def add_node def add_node
primary = get_node_with_state(1) primary = get_node_with_state(1)
con = get_connection(primary) con = get_connection(primary)