コード例 #1
0
def test_basic_locking(fake_redis):
    """Check if single process locking works"""
    root_prox = Proxy(path=('QualityControl', ))
    root_prox.clear()

    root_prox.acquire()
    assert root_prox.is_locked()
    root_prox.set('child', {})
    root_prox.release()
コード例 #2
0
def test_parallel_lock(real_redis):
    """Test if two processes really block on a common ressource"""
    val = Proxy('LockMe').set("x", 0)

    checks = defaultdict(bool)

    def _lock_me():
        """See if the thread could acquire the lock at last"""
        time.sleep(0.5)
        val.acquire()
        val.release()
        checks["thread-got-through"] = True

    jobs = 2
    with background_thread(_lock_me, (), jobs=jobs - 1):
        val.acquire()
        time.sleep(2)
        val.release()
        time.sleep(0.5)

    assert checks["thread-got-through"]