2011-03-18 02:38:21 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require 'mongo'
|
|
|
|
require 'test/unit'
|
2012-04-11 15:08:04 +00:00
|
|
|
require File.expand_path("../../test_helper", __FILE__)
|
2011-03-18 02:38:21 +00:00
|
|
|
|
|
|
|
class ForkTest < Test::Unit::TestCase
|
|
|
|
include Mongo
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@conn = standard_connection
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fork
|
|
|
|
# Now insert some data
|
|
|
|
10.times do |n|
|
|
|
|
@conn[MONGO_TEST_DB]['nums'].insert({:a => n})
|
|
|
|
end
|
|
|
|
|
|
|
|
# Now fork. You'll almost always see an exception here.
|
|
|
|
if !Kernel.fork
|
|
|
|
10.times do
|
|
|
|
assert @conn[MONGO_TEST_DB]['nums'].find_one
|
|
|
|
end
|
|
|
|
else
|
|
|
|
10.times do
|
|
|
|
assert @conn[MONGO_TEST_DB]['nums'].find_one
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|