예제 #1
0
def test_reacquire(conn_6379):
    redis_lock = Redistock(conn_6379, LockKey, ttl=1, timeout=0.1)
    redis_lock.acquire()
    assert redis_lock.lock
    redis_lock.acquire()
    assert redis_lock.lock
    redis_lock.release()
    assert not redis_lock.lock
예제 #2
0
def test_different_server(conn_6379, conn_6380):
    with Redistock(conn_6379, LockKey, ttl=10) as lock_6379:
        assert lock_6379
        with Redistock(conn_6380, LockKey, timeout=1) as lock_6380:
            assert lock_6380
예제 #3
0
def test_timeout_lt_ttl(conn_6379):
    with Redistock(conn_6379, LockKey, ttl=3):
        redis_lock = Redistock(conn_6379, LockKey, timeout=2)
        assert not redis_lock.acquire()
        redis_lock.release()
예제 #4
0
def test_timeout_gt_ttl(conn_6379):
    with Redistock(conn_6379, LockKey, ttl=0.001):
        redis_lock = Redistock(conn_6379, LockKey, timeout=1)
        assert redis_lock.acquire()
        redis_lock.release()
예제 #5
0
def test_timeout_lock(conn_6379):
    with Redistock(conn_6379, LockKey, ttl=1):
        redis_lock = Redistock(conn_6379, LockKey, timeout=2, delay=0.5)
        lock = redis_lock.acquire()
        assert lock
        redis_lock.release()
예제 #6
0
def test_with_acquire_error(conn_6379):
    with Redistock(conn_6379, LockKey, ttl=10):
        with pytest.raises(RedistockNotObtained):
            with Redistock(conn_6379, LockKey, timeout=1) as lock:
                assert not lock
예제 #7
0
def test_no_block(conn_6379):
    with Redistock(conn_6379, LockKey, ttl=10):
        assert not Redistock(conn_6379, LockKey, block=False).acquire()
예제 #8
0
def test_with_statement(conn_6379):
    redis_lock = Redistock(conn_6379, LockKey, ttl=10)
    with redis_lock as lock:
        assert lock
    assert not redis_lock.lock
예제 #9
0
def test_basic(conn_6379):
    redis_lock = Redistock(conn_6379, LockKey, ttl=1)
    redis_lock.acquire()
    assert redis_lock.lock
    redis_lock.release()
    assert not redis_lock.lock