From 8495e75e5eaba56df4ae7b43da47afae219e0053 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Thu, 4 Feb 2010 18:03:12 -0500 Subject: [PATCH] fixed reconnect for queries --- test/auxillary/autoreconnect_test.rb | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/auxillary/autoreconnect_test.rb diff --git a/test/auxillary/autoreconnect_test.rb b/test/auxillary/autoreconnect_test.rb new file mode 100644 index 0000000..729c883 --- /dev/null +++ b/test/auxillary/autoreconnect_test.rb @@ -0,0 +1,42 @@ +$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'mongo' +require 'test/unit' +require 'test/test_helper' + +# NOTE: This test requires bouncing the server +class AutoreconnectTest < Test::Unit::TestCase + include Mongo + + def setup + @conn = Mongo::Connection.new + @db = @conn.db('mongo-ruby-test') + @db.drop_collection("test-connect") + @coll = @db.collection("test-connect") + end + + def test_query + @coll.save({:a => 20}) + @coll.save({:a => 30}) + @coll.save({:a => 40}) + 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 + + puts "Please disconnect and then reconnect the current master." + gets + + begin + @coll.find.to_a + rescue Mongo::ConnectionFailure + end + + 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 + end + +end