Sha256: 2c2b683e5c4400fe2d5d175bb8d6cd4d7428bf6734b1995b0f5686281f872ea9

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

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 ReplicaSetQueryTest < 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
    @coll.save({:a => 20}, :safe => {:w => 3})
    @coll.save({:a => 30}, :safe => {:w => 3})
    @coll.save({:a => 40}, :safe => {:w => 3})
    results = []
    @coll.find.each {|r| results << r}
    [20, 30, 40].each do |a|
      assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
    end

    RS.kill_primary

    results = []
    rescue_connection_failure do
      @coll.find.each {|r| results << r}
      [20, 30, 40].each do |a|
        assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
      end
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongo-1.2.4 test/replica_sets/query_test.rb
mongo-1.2.3 test/replica_sets/query_test.rb
mongo-1.2.2 test/replica_sets/query_test.rb
mongo-1.2.1 test/replica_sets/query_test.rb
mongo-1.2.0 test/replica_sets/query_test.rb
mongo-1.2.rc2 test/replica_sets/query_test.rb
mongo-1.2.rc1 test/replica_sets/query_test.rb
mongo-1.2.rc0 test/replica_sets/query_test.rb
mongo-1.1.5 test/replica_sets/query_test.rb