Sha256: ce366bf19a2cdfebf36150a915e96333df6742fef726ddea65e32828ee89b53a

Contents?: true

Size: 987 Bytes

Versions: 7

Compression:

Stored size: 987 Bytes

Contents

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

# NOTE: This test expects a replica set of three nodes to be running
# on the local host.
class ReplicaSetCountTest < Test::Unit::TestCase
  include Mongo

  def setup
    @conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]], [RS.host, RS.ports[2]])
    @db = @conn.db(MONGO_TEST_DB)
    @db.drop_collection("test-sets")
    @coll = @db.collection("test-sets")
  end

  def teardown
    RS.restart_killed_nodes
    @conn.close if @conn
  end

  def test_correct_count_after_insertion_reconnect
    @coll.insert({:a => 20}, :safe => {:w => 2, :wtimeout => 10000})
    assert_equal 1, @coll.count

    # Kill the current master node
    @node = RS.kill_primary

    rescue_connection_failure do
      @coll.insert({:a => 30}, :safe => true)
    end

    @coll.insert({:a => 40}, :safe => true)
    assert_equal 3, @coll.count, "Second count failed"
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
jmongo-1.1.5 test/replica_sets/count_test.rb
jmongo-1.1.4 test/replica_sets/count_test.rb
jmongo-1.1.3 test/replica_sets/count_test.rb
jmongo-1.1.2 test/replica_sets/count_test.rb
jmongo-1.1.1 test/replica_sets/count_test.rb
jmongo-1.1.0 test/replica_sets/count_test.rb
mongo-1.4.0 test/replica_sets/count_test.rb