예제 #1
0
 def test_with(self):
     m = DynamoDbMutex(name=random_name(), holder=random_name())
     try:
         with m:
             time.sleep(3)
             raise
     except:
         print("In exception handler")
         self.assertFalse(m.is_locked())
예제 #2
0
 def test_release_expired(self):
     name = random_name()
     caller = "caller1"
     m1 = DynamoDbMutex(name=name, holder=caller, timeoutms=2 * 1000)
     m1.lock()
     time.sleep(3)
     caller = "caller2"
     m2 = DynamoDbMutex(name=name, holder=caller, timeoutms=2 * 1000)
     self.assertTrue(m2.lock())
     m1.release()
     self.assertTrue(m2.is_locked())
     m2.release()
예제 #3
0
 def test_with_fail(self):
     name = random_name()
     m1 = DynamoDbMutex(name=name, holder=random_name())
     m1.lock()
     m2 = DynamoDbMutex(name=name, holder=random_name())
     exceptionHappened = False
     try:
         with m2:
             time.sleep(3)
     except AcquireLockFailedError:
         print("In exception handler")
         self.assertFalse(m2.is_locked())
         exceptionHappened = True
     self.assertTrue(exceptionHappened)