Example #1
0
def test_wait_for_unlock(tmpdir, lock_type):
    lockdir = str(get_lockdirs(tmpdir, amount=1)[0])
    blocking_key, good_key = [str(key) for key in get_keys(tmpdir, amount=2)]

    trylock_exclusive(lockdir, blocking_key)

    def blocker_agent():
        try:
            trylock_exclusive(lockdir, blocking_key)
            time.sleep(0.5)
            unlock(lockdir, blocking_key)
        finally:
            sys.exit(0)

    proc = multiprocessing.Process(target=blocker_agent)
    start = time.time()
    proc.start()
    dirlock.lock(lockdir, LOCK_TYPES[lock_type], good_key)
    end = time.time()
    proc.join()

    assert (end - start) > 0.5
Example #2
0
def test_wait_for_unlock(tmpdir, lock_type):
    lockdir = str(get_lockdirs(tmpdir, amount=1)[0])
    blocking_key, good_key = [str(key) for key in get_keys(tmpdir, amount=2)]

    trylock_exclusive(lockdir, blocking_key)

    def blocker_agent():
        try:
            trylock_exclusive(lockdir, blocking_key)
            time.sleep(0.5)
            unlock(lockdir, blocking_key)
        finally:
            sys.exit(0)

    proc = multiprocessing.Process(target=blocker_agent)
    start = time.time()
    proc.start()
    dirlock.lock(lockdir, LOCK_TYPES[lock_type], good_key)
    end = time.time()
    proc.join()

    assert (end - start) > 0.5
Example #3
0
def lock_uuid(testdir, excl):
    return dirlock.lock(testdir, excl, prefix.paths.uuid())