tests/test-lock.py
branchstable
changeset 32088 0d892d820a51
parent 31259 e067741d4607
child 32319 68c43a416585
equal deleted inserted replaced
32087:e1938d6051da 32088:0d892d820a51
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 import copy
     3 import copy
       
     4 import errno
     4 import os
     5 import os
     5 import silenttestrunner
     6 import silenttestrunner
     6 import tempfile
     7 import tempfile
     7 import types
     8 import types
     8 import unittest
     9 import unittest
   265 
   266 
   266         self.assertRaises(error.LockInheritanceContractViolation, tryinherit)
   267         self.assertRaises(error.LockInheritanceContractViolation, tryinherit)
   267 
   268 
   268         lock.release()
   269         lock.release()
   269 
   270 
       
   271     def testfrequentlockunlock(self):
       
   272         """This tests whether lock acquisition fails as expected, even if
       
   273         (1) lock can't be acquired (makelock fails by EEXIST), and
       
   274         (2) locker info can't be read in (readlock fails by ENOENT) while
       
   275         retrying 5 times.
       
   276         """
       
   277 
       
   278         d = tempfile.mkdtemp(dir=os.getcwd())
       
   279         state = teststate(self, d)
       
   280 
       
   281         def emulatefrequentlock(*args):
       
   282             raise OSError(errno.EEXIST, "File exists")
       
   283         def emulatefrequentunlock(*args):
       
   284             raise OSError(errno.ENOENT, "No such file or directory")
       
   285 
       
   286         state.vfs.makelock = emulatefrequentlock
       
   287         state.vfs.readlock = emulatefrequentunlock
       
   288 
       
   289         try:
       
   290             state.makelock(timeout=0)
       
   291             self.fail("unexpected lock acquisition")
       
   292         except error.LockHeld as why:
       
   293             self.assertTrue(why.errno == errno.ETIMEDOUT)
       
   294             self.assertTrue(why.locker == "")
       
   295             state.assertlockexists(False)
       
   296 
   270 if __name__ == '__main__':
   297 if __name__ == '__main__':
   271     silenttestrunner.main(__name__)
   298     silenttestrunner.main(__name__)