def testExclusive(self): """ util.lock: ExclusiveLock: lock is exclusive """ first = ExclusiveLock(self.lock_dir) second = ExclusiveLock(self.lock_dir) if not first.acquire(0.1): raise TestSkiped("can't acquire lock") self.failIf(second.acquire(0.1), "first lock is not exclusive")
def testExclusive(self): """ util.lock: ExclusiveLock: lock is exclusive """ first = ExclusiveLock(self.lock_dir) second = ExclusiveLock(self.lock_dir) if not first.acquire(0.1): py.test.skip("can't acquire lock") assert not second.acquire(0.1)
def testExpire(self): """ util.lock: ExclusiveLock: expire """ timeout = 2.0 lock = ExclusiveLock(self.lock_dir, timeout=timeout) if not lock.acquire(0.1): py.test.skip("can't acquire lock") assert not lock.expire() time.sleep(timeout) assert lock.expire()
def testExpire(self): """ util.lock: ExclusiveLock: expire """ timeout = 2.0 lock = ExclusiveLock(self.lock_dir, timeout=timeout) if not lock.acquire(0.1): raise TestSkiped("can't acquire lock") self.failIf(lock.expire(), "lock should not be expired yet") time.sleep(timeout) self.failUnless(lock.expire(), "lock should be expired")
def testRelease(self): """ util.lock: ExclusiveLock: release After releasing a lock, new one could be acquired. """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): py.test.skip("can't acquire lock") lock.release() assert lock.acquire(0.1)
def testRelease(self): """ util.lock: ExclusiveLock: release After releasing a lock, new one could be acquired. """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): raise TestSkiped("can't acquire lock") lock.release() self.failUnless(lock.acquire(0.1), "Could not acquire lock after release")
def testAcquireAfterTimeout(self): """ util.lock: ExclusiveLock: acquire after timeout Lock with one lock, try to acquire another after timeout. """ timeout = 2.0 # minimal timout first = ExclusiveLock(self.lock_dir, timeout) second = ExclusiveLock(self.lock_dir, timeout) if not first.acquire(0.1): py.test.skip("can't acquire lock") if second.acquire(0.1): py.test.skip("first lock is not exclusive") # Second lock should be acquired after timeout assert second.acquire(timeout + 0.2)
def testIsLocked(self): """ util.lock: ExclusiveLock: isLocked """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): py.test.skip("can't acquire lock") assert lock.isLocked() lock.release() assert not lock.isLocked()
def testIsLocked(self): """ util.lock: ExclusiveLock: isLocked """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): raise TestSkiped("can't acquire lock") self.failUnless(lock.isLocked(), "lock state wrong") lock.release() self.failIf(lock.isLocked(), "lock state wrong")
def _do_locked(self, lockname, fn, arg): l = ExclusiveLock(lockname, 30) l.acquire(30) try: ret = fn(arg) finally: l.release() return ret
def testAcquireAfterTimeout(self): """ util.lock: ExclusiveLock: acquire after timeout Lock with one lock, try to acquire another after timeout. """ timeout = 2.0 # minimal timout first = ExclusiveLock(self.lock_dir, timeout) second = ExclusiveLock(self.lock_dir, timeout) if not first.acquire(0.1): py.test.skip("can't acquire lock") if second.acquire(0.1): py.test.skip("first lock is not exclusive") # Second lock should be acquired after timeout assert second.acquire(timeout + 0.1)
def testExists(self): """ util.lock: ExclusiveLock: exists """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): py.test.skip("can't acquire lock") assert lock.exists()
def testExists(self): """ util.lock: ExclusiveLock: exists """ lock = ExclusiveLock(self.lock_dir) if not lock.acquire(0.1): raise TestSkiped("can't acquire lock") self.failUnless(lock.exists(), "lock should exists")
def testAcquire(self): """ util.lock: ExclusiveLock: acquire """ lock = ExclusiveLock(self.lock_dir) assert lock.acquire(0.1)
def _change_item_metadata(self, item): if not item._fs_item_id is None: lp = os.path.join(self._path, item._fs_item_id, 'meta.lock') item._fs_metadata_lock = ExclusiveLock(lp, 30) item._fs_metadata_lock.acquire(30)
def testAcquire(self): """ util.lock: ExclusiveLock: acquire """ lock = ExclusiveLock(self.lock_dir) self.failUnless(lock.acquire(0.1), "Could not acquire lock")
def _change_item_metadata(self, item): if not item._fs_item_id is None: lp = self._make_path('meta', item._fs_item_id, 'item.lock') item._fs_metadata_lock = ExclusiveLock(lp, 30) item._fs_metadata_lock.acquire(30)