def test_locked(self): lock = sherlock.EtcdLock(self.lock_name) lock._acquire() self.assertTrue(lock._locked) lock._release() self.assertFalse(lock._locked)
def test_acquire(self): lock = sherlock.EtcdLock(self.lock_name) self.assertTrue(lock._acquire()) self.assertEqual(self.client.get(self.lock_name).value, str(lock._owner))
def test_release_with_namespace(self): lock = sherlock.EtcdLock(self.lock_name, namespace='ns') lock._acquire() lock._release() self.assertRaises(etcd.EtcdKeyNotFound, self.client.get, '/ns/%s' % self.lock_name)
def test_release_own_only(self): lock1 = sherlock.EtcdLock(self.lock_name) lock2 = sherlock.EtcdLock(self.lock_name) lock1._acquire() self.assertRaises(sherlock.LockException, lock2._release) lock1._release()
def test_release(self): lock = sherlock.EtcdLock(self.lock_name) lock._acquire() lock._release() self.assertRaises(etcd.EtcdKeyNotFound, self.client.get, self.lock_name)
def test_acquire_check_expire_is_not_set(self): lock = sherlock.EtcdLock(self.lock_name, expire=None) lock.acquire() time.sleep(2) self.assertEquals(self.client.get(self.lock_name).ttl, None)
def test_acquire_check_expiry(self): lock = sherlock.EtcdLock(self.lock_name, expire=1) lock.acquire() time.sleep(2) self.assertFalse(lock.locked())
def test_acquire_once_only(self): lock1 = sherlock.EtcdLock(self.lock_name) lock2 = sherlock.EtcdLock(self.lock_name) self.assertTrue(lock1._acquire()) self.assertFalse(lock2._acquire())
def test_acquire_with_namespace(self): lock = sherlock.EtcdLock(self.lock_name, namespace='ns') self.assertTrue(lock._acquire()) self.assertEqual(self.client.get('/ns/%s' % self.lock_name).value, str(lock._owner))