2011-11-16 23:10:16 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/replica_sets/rs_test_helper'
|
|
|
|
require 'benchmark'
|
|
|
|
|
|
|
|
class ReplicaSetRefreshWithThreadsTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
2012-01-30 00:05:17 +00:00
|
|
|
ensure_rs
|
2011-11-16 23:10:16 +00:00
|
|
|
@conn = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2011-11-16 23:10:16 +00:00
|
|
|
@conn.close if @conn
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_write_load_with_added_nodes
|
2012-02-18 23:29:52 +00:00
|
|
|
seeds = build_seeds(3)
|
|
|
|
args = {
|
|
|
|
:refresh_interval => 5,
|
|
|
|
:refresh_mode => :sync,
|
|
|
|
:read => :secondary
|
|
|
|
}
|
|
|
|
@conn = ReplSetConnection.new(seeds, args)
|
2011-11-16 23:10:16 +00:00
|
|
|
@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 = []
|
2011-11-18 20:47:06 +00:00
|
|
|
10.times do
|
2011-11-16 23:10:16 +00:00
|
|
|
threads << Thread.new do
|
2011-11-18 20:47:06 +00:00
|
|
|
1000.times do |i|
|
2011-11-16 23:10:16 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.add_node
|
2011-11-18 20:47:06 +00:00
|
|
|
threads.each {|t| t.join }
|
|
|
|
|
2011-11-16 23:10:16 +00:00
|
|
|
config = @conn['admin'].command({:ismaster => 1})
|
|
|
|
|
|
|
|
assert_equal 3, @conn.secondary_pools.length
|
|
|
|
assert_equal 3, @conn.secondaries.length
|
|
|
|
end
|
|
|
|
end
|