RUBY-286 test replica set reconnect when adding a new node

This commit is contained in:
Kyle Banker 2011-06-17 12:15:07 -04:00
parent fbf7b754ac
commit 4f4e6ee833
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,33 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require './test/replica_sets/rs_test_helper'
class ReplicaSetReconfigureTest < Test::Unit::TestCase
include Mongo
def setup
@conn = ReplSetConnection.new([RS.host, RS.ports[0]])
@db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@coll = @db.collection("test-sets")
end
def teardown
RS.restart_killed_nodes
end
def test_query
assert @coll.save({:a => 1}, :safe => {:w => 3})
RS.add_node
assert_raise_error(Mongo::ConnectionFailure, "") do
@coll.save({:a => 1}, :safe => {:w => 3})
end
assert @coll.save({:a => 1}, :safe => {:w => 3})
end
def benchmark_queries
t1 = Time.now
10000.times { @coll.find_one }
Time.now - t1
end
end

View File

@ -103,6 +103,25 @@ class ReplSetManager
@mongods[n]['start']
end
def add_node
primary = get_node_with_state(1)
con = get_connection(primary)
init_node(@mongods.length)
config = con['local']['system.replset'].find_one
@config['version'] = config['version'] + 1
p "Old config: #{config}"
p "New config: #{@config}"
# We expect a connection failure on reconfigure here.
begin
con['admin'].command({'replSetReconfig' => @config})
rescue Mongo::ConnectionFailure
end
ensure_up
end
def kill(node, signal=2)
pid = @mongods[node]['pid']
puts "** Killing node with pid #{pid} at port #{@mongods[node]['port']}"