RUBY-286 test replica set reconnect when adding a new node
This commit is contained in:
parent
fbf7b754ac
commit
4f4e6ee833
|
@ -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
|
|
@ -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']}"
|
||||
|
|
Loading…
Reference in New Issue