Sha256: cf68bc05907a540e5a0834fb32739295ddf4387f6f150912057ae9c777e9dc2e

Contents?: true

Size: 1.46 KB

Versions: 47

Compression:

Stored size: 1.46 KB

Contents

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require './test/replica_sets/rs_test_helper'
require 'benchmark'

class ReplicaSetRefreshWithThreadsTest < Test::Unit::TestCase

  def setup
    ensure_rs
    @conn = nil
  end

  def teardown
    @conn.close if @conn
  end

  def test_read_write_load_with_added_nodes
    # MongoDB < 2.0 will disconnect clients on rs.reconfig()
    return true if @rs.version.first < 2

    seeds = build_seeds(3)
    args = {
      :refresh_interval => 5,
      :refresh_mode => :sync,
      :read => :secondary
    }
    @conn = ReplSetConnection.new(seeds, args)
    @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 = []
    10.times do
      threads << Thread.new do
        1000.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
      end
    end

    @rs.add_node
    threads.each {|t| t.join }
    
    @conn['admin'].command({:ismaster => 1})

    assert_equal 3, @conn.secondary_pools.length
    assert_equal 3, @conn.secondaries.length
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.7.4 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.7.3 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.7.2 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.7.1 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.7.0 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.9 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.8 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.7 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.6 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.5 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.4 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.3 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.2 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.1 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.6.0 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.5.17 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.5.16 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.5.15 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb
classiccms-0.5.14 vendor/bundle/gems/mongo-1.6.2/test/replica_sets/refresh_with_threads_test.rb