예제 #1
0
def test_with_success(tmpdir_factory):
    folder = Path(tmpdir_factory.mktemp('lock'))
    lock_file = folder.joinpath('.lock')

    with lock(lock_file) as l:
        assert l.locked
        assert lock_file.exists()
    assert not l.locked
    assert not lock_file.exists()
예제 #2
0
def test_release_when_not_lockded(tmpdir_factory):
    folder = Path(tmpdir_factory.mktemp('lock'))
    lock_file = folder.joinpath('.lock')

    l = lock(lock_file)
    assert not l.locked
    l.release()
    assert not l.locked
    assert not lock_file.exists()
예제 #3
0
def backup_db_as_csv_to_github(exclude=None):
    repo_path = current_app.config['ACONDBS_DB_BACKUP_CSV_GIT_FOLDER']
    lock_path = current_app.config['ACONDBS_DB_BACKUP_CSV_GIT_LOCK']
    timeout = current_app.config['ACONDBS_DB_BACKUP_CSV_GIT_LOCK_TIMEOUT']
    try:
        with lock.lock(lock_path, timeout=timeout):
            backup_db_as_csv_to_github_(repo_path, exclude)
    except lock.TimeOutAcquiringLock:
        warnings.warn('Time out! unable to acquire the lock in {} seconds: {}'.format(timeout, lock_path))
예제 #4
0
def test_acquire_timeout(tmpdir_factory):
    timeout = 0.1  # sec

    folder = Path(tmpdir_factory.mktemp('lock'))
    lock_file = folder.joinpath('.lock')

    lock_file.touch()

    l = lock(lock_file, timeout=timeout)

    with pytest.raises(TimeOutAcquiringLock):
        l.acquire()
예제 #5
0
def test_acquire_release(tmpdir_factory):
    folder = Path(tmpdir_factory.mktemp('lock'))
    lock_file = folder.joinpath('.lock')

    l = lock(lock_file)
    assert not l.locked
    l.acquire()
    assert l.locked
    assert lock_file.exists()
    l.release()
    assert not l.locked
    assert not lock_file.exists()