diff --git a/Rakefile b/Rakefile index fd06a8d..faf6f31 100644 --- a/Rakefile +++ b/Rakefile @@ -19,6 +19,7 @@ desc "Test the MongoDB Ruby driver." task :test do Rake::Task['test:unit'].invoke Rake::Task['test:functional'].invoke + Rake::Task['test:pooled_threading'].invoke end namespace :test do @@ -32,6 +33,11 @@ namespace :test do t.verbose = true end + Rake::TestTask.new(:pooled_threading) do |t| + t.test_files = FileList['test/threading/*.rb'] + t.verbose = true + end + Rake::TestTask.new(:pair_count) do |t| t.test_files = FileList['test/replica/count_test.rb'] t.verbose = true diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index c15a638..0b564f6 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -383,7 +383,7 @@ module Mongo next if @checked_out.size < @sockets.size # Otherwise, wait. - if @queue.wait(@timeout) + if wait next else @@ -399,6 +399,20 @@ module Mongo end # synchronize end + if RUBY_VERSION >= '1.9' + # Ruby 1.9's Condition Variables don't support timeouts yet; + # until they do, we'll make do with this hack. + def wait + Timeout.timeout(@timeout) do + @queue.wait + end + end + else + def wait + @queue.wait(@timeout) + end + end + def receive(sock) receive_header(sock) number_received, cursor_id = receive_response_header(sock) diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index da40a5f..aba526c 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -305,7 +305,7 @@ module Mongo sel = {:ns => full_collection_name(collection_name)} info = {} Cursor.new(Collection.new(self, SYSTEM_INDEX_COLLECTION), :selector => sel).each { |index| - info[index['name']] = index['key'].map + info[index['name']] = index['key'].map {|k| k} } info end diff --git a/test/test_threading_large_pool.rb b/test/threading/test_threading_large_pool.rb similarity index 82% rename from test/test_threading_large_pool.rb rename to test/threading/test_threading_large_pool.rb index 8a3d177..8ca5cb0 100644 --- a/test/test_threading_large_pool.rb +++ b/test/threading/test_threading_large_pool.rb @@ -43,21 +43,21 @@ class TestThreadingLargePool < Test::Unit::TestCase end def test_safe_insert - set_up_safe_data - threads = [] - 100.times do |i| - threads[i] = Thread.new do - if i % 2 == 0 - assert_raise Mongo::OperationFailure do - @unique.insert({"test" => "insert"}, :safe => true) - end - else - @duplicate.insert({"test" => "insert"}, :safe => true) + set_up_safe_data + threads = [] + 100.times do |i| + threads[i] = Thread.new do + 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 - - 100.times do |i| + end + + 100.times do |i| threads[i].join end end