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__) |