Example #1
0
 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")                
Example #2
0
 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)
Example #3
0
 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()
Example #4
0
 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")
Example #5
0
 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()
Example #6
0
    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)
Example #7
0
 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")
Example #8
0
    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)
Example #9
0
 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()
Example #10
0
 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)
Example #11
0
 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")
Example #12
0
 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()
Example #13
0
    def _do_locked(self, lockname, fn, arg):
        l = ExclusiveLock(lockname, 30)
        l.acquire(30)
        try:
            ret = fn(arg)
        finally:
            l.release()

        return ret
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
 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()
Example #17
0
 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")
Example #18
0
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     assert lock.acquire(0.1)
Example #19
0
 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)
Example #20
0
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     assert lock.acquire(0.1)
Example #21
0
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     self.failUnless(lock.acquire(0.1), "Could not acquire lock")
Example #22
0
 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()
Example #23
0
 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)