예제 #1
0
    def test_basic(self):
        timeout = 10
        lock = Lock('basic', timeout=timeout)

        assert lock.held is False
        assert lock.seconds_remaining is 0

        assert lock.acquire() is True
        assert timeout > lock.seconds_remaining > (timeout - 0.1)
        assert lock.held is True

        assert lock.acquire() is True  # ensure reentrancy

        assert lock.release() is True
        assert lock.seconds_remaining is 0
        assert lock.held is False
        assert lock.release() is False
예제 #2
0
파일: redis.py 프로젝트: timchunght/sentry
 def try_lock(item):
     """
     Attempt to immedately acquire a lock on the timeline at
     key, returning the lock if it can be acquired, otherwise
     returning ``None``.
     """
     key, timestamp = item
     lock = Lock(make_timeline_key(self.namespace, key), timeout=5, nowait=True)
     return lock if lock.acquire() else None, item
예제 #3
0
    def test_basic(self):
        timeout = 10
        lock = Lock('basic', timeout=timeout)

        assert lock.held is False
        assert lock.seconds_remaining is 0

        assert lock.acquire() is True
        assert timeout > lock.seconds_remaining > (timeout - 0.1)
        assert lock.held is True

        with pytest.raises(LockAlreadyHeld):
            lock.acquire()

        assert lock.release() is True
        assert lock.seconds_remaining is 0
        assert lock.held is False
        assert lock.release() is False