Added replica set refresh test for threaded app.
This commit is contained in:
parent
5dbe563d14
commit
177fad34ff
56
test/replica_sets/refresh_with_threads_test.rb
Normal file
56
test/replica_sets/refresh_with_threads_test.rb
Normal file
@ -0,0 +1,56 @@
|
||||
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
require './test/replica_sets/rs_test_helper'
|
||||
require 'benchmark'
|
||||
|
||||
class ReplicaSetRefreshWithThreadsTest < Test::Unit::TestCase
|
||||
include ReplicaSetTest
|
||||
|
||||
def setup
|
||||
@conn = nil
|
||||
end
|
||||
|
||||
def teardown
|
||||
self.rs.restart_killed_nodes
|
||||
@conn.close if @conn
|
||||
end
|
||||
|
||||
def test_read_write_load_with_added_nodes
|
||||
@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 => :async,
|
||||
:read => :secondary)
|
||||
@duplicate = @conn[MONGO_TEST_DB]['duplicate']
|
||||
@unique = @conn[MONGO_TEST_DB]['unique']
|
||||
@duplicate.insert("test" => "insert")
|
||||
@duplicate.insert("test" => "update")
|
||||
@unique.insert("test" => "insert")
|
||||
@unique.insert("test" => "update")
|
||||
@unique.create_index("test", :unique => true)
|
||||
|
||||
threads = []
|
||||
100.times do
|
||||
threads << Thread.new do
|
||||
100.times do |i|
|
||||
if i % 2 == 0
|
||||
assert_raise Mongo::OperationFailure do
|
||||
@unique.insert({"test" => "insert"}, :safe => true)
|
||||
end
|
||||
else
|
||||
@duplicate.insert({"test" => "insert"}, :safe => true)
|
||||
end
|
||||
end
|
||||
@conn.end_request
|
||||
end
|
||||
end
|
||||
|
||||
self.rs.add_node
|
||||
sleep(4)
|
||||
config = @conn['admin'].command({:ismaster => 1})
|
||||
|
||||
assert_equal 3, @conn.secondary_pools.length
|
||||
assert_equal 3, @conn.secondaries.length
|
||||
|
||||
threads.each {|t| t.join }
|
||||
end
|
||||
end
|
@ -155,8 +155,8 @@ class ReplSetManager
|
||||
def add_node(n=nil)
|
||||
primary = get_node_with_state(1)
|
||||
con = get_connection(primary)
|
||||
init_node(n || @mongods.length)
|
||||
|
||||
init_node(n || @mongods.length)
|
||||
config = con['local']['system.replset'].find_one
|
||||
@config['version'] = config['version'] + 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user