RUBY-184 Connection#locked?

This commit is contained in:
Kyle Banker 2010-10-04 11:38:20 -04:00
parent 2ed0adbbc6
commit 7ad280c2cb
2 changed files with 10 additions and 0 deletions

View File

@ -222,6 +222,13 @@ module Mongo
self['admin'].command(cmd)
end
# Is this database locked against writes?
#
# @return [Boolean]
def locked?
self['admin']['$cmd.sys.inprog'].find_one['fsyncLock'] == 1
end
# Unlock a previously fsync-locked mongod process.
#
# @return [BSON::OrderedHash] command response

View File

@ -144,7 +144,9 @@ class TestConnection < Test::Unit::TestCase
end
def test_fsync_lock
assert !@mongo.locked?
@mongo.lock!
assert @mongo.locked?
assert_equal 1, @mongo['admin']['$cmd.sys.inprog'].find_one['fsyncLock'], "Not fsync-locked"
assert_equal "unlock requested", @mongo.unlock!['info']
unlocked = false
@ -158,6 +160,7 @@ class TestConnection < Test::Unit::TestCase
counter += 1
end
end
assert !@mongo.locked?
assert unlocked, "mongod failed to unlock"
end