Exemple #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):
         py.test.skip("can't acquire lock")
     assert not second.acquire(0.1)
 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")                
Exemple #3
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)
Exemple #4
0
    def _do_locked(self, lockname, fn, arg):
        l = ExclusiveLock(lockname, 30)
        l.acquire(30)
        try:
            ret = fn(arg)
        finally:
            l.release()

        return ret
Exemple #5
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)
Exemple #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)
 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")
Exemple #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)
Exemple #9
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)
 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")
Exemple #11
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()
Exemple #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()
 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")
Exemple #14
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()
Exemple #15
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()
Exemple #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()
 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")
Exemple #18
0
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     assert lock.acquire(0.1)
Exemple #19
0
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     assert lock.acquire(0.1)
Exemple #20
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()
 def testAcquire(self):
     """ util.lock: ExclusiveLock: acquire """
     lock = ExclusiveLock(self.lock_dir)
     self.failUnless(lock.acquire(0.1), "Could not acquire lock")