예제 #1
0
def test_f2_lbs_atomicity_2():
    sys.settrace(make_trace_func('test_f2_lbs_atomicity_2', abort))
    with itest_setup(test_file_history, ):
        backup(BACKUP_ARGS)
    file_data_path = os.path.join(DATA_DIR, 'new_file_2')
    file_backup_path = os.path.join(
        BACKUP_DIR,
        sha_to_path(test_file_history[file_data_path][0].sha),
    )
    assert os.path.exists(file_backup_path)
예제 #2
0
def test_m1_crash_before_save():
    sys.settrace(make_trace_func('test_m1_crash_before_save', abort))
    with itest_setup(
            test_file_history,
            _TestFileData('foo', 'asdfhjkl'),
    ), pytest.raises(Exception):
        backup(BACKUP_ARGS)
    assert_manifest_correct(before=True)
    file_data_path = os.path.join(DATA_DIR, 'foo')
    file_backup_path = os.path.join(
        BACKUP_DIR,
        sha_to_path(test_file_history[file_data_path][1].sha),
    )
    assert os.path.exists(file_backup_path)
예제 #3
0
def test_m2_crash_after_file_save():
    sys.settrace(make_trace_func('test_m2_crash_after_file_save', abort))
    with itest_setup(test_file_history):
        backup(BACKUP_ARGS)
    manifest_conn = sqlite3.connect(get_latest_manifest())
    manifest_conn.row_factory = sqlite3.Row
    manifest_cursor = manifest_conn.cursor()

    manifest_cursor.execute(
        'select * from manifest where abs_file_name like "%another_file"')
    rows = manifest_cursor.fetchall()
    assert len(rows) == 1
    assert rows[0]['sha'] == test_file_history[os.path.join(
        DATA_DIR, 'another_file')][0].sha
예제 #4
0
def test_m2_crash_before_file_save():
    sys.settrace(make_trace_func('test_m2_crash_before_file_save', abort))
    with itest_setup(
            test_file_history,
            _TestFileData('another_file', '1234'),
    ):
        backup(BACKUP_ARGS)
    manifest_conn = sqlite3.connect(get_latest_manifest())
    manifest_conn.row_factory = sqlite3.Row
    manifest_cursor = manifest_conn.cursor()

    manifest_cursor.execute(
        'select * from manifest where abs_file_name like "%another_file"')
    rows = manifest_cursor.fetchall()
    assert not rows
예제 #5
0
def test_f3_file_changed_while_saving():
    sys.settrace(
        make_trace_func(
            'test_f3_file_changed_while_saving',
            make_modify_file_func(os.path.join(DATA_DIR, 'new_file_3')),
        ))
    with itest_setup(
            test_file_history,
            _TestFileData('new_file_3', '12345'),
    ):
        backup(BACKUP_ARGS)
    file_data_path = os.path.join(DATA_DIR, 'new_file_3')
    file_backup_path = os.path.join(
        BACKUP_DIR,
        sha_to_path(test_file_history[file_data_path][0].sha),
    )
    assert not os.path.exists(file_backup_path)
예제 #6
0
def test_f1_crash_file_save():
    sys.settrace(make_trace_func('test_f1_crash_file_save', abort))
    with itest_setup(
            test_file_history,
            _TestFileData('foo', 'asdfhjkl'),
            _TestFileData('new_file', 'zxcv'),
    ):
        backup(BACKUP_ARGS)

    first_file_data_path = os.path.join(DATA_DIR, 'foo')
    second_file_data_path = os.path.join(DATA_DIR, 'new_file')
    first_file_backup_path = os.path.join(
        BACKUP_DIR,
        sha_to_path(test_file_history[first_file_data_path][1].sha),
    )
    second_file_backup_path = os.path.join(
        BACKUP_DIR,
        sha_to_path(test_file_history[second_file_data_path][0].sha),
    )
    assert not os.path.exists(first_file_backup_path)
    assert os.path.exists(second_file_backup_path)

    # reset everything back to "normal" before the next test
    backup(BACKUP_ARGS)
예제 #7
0
def test_m1_crash_after_save():
    sys.settrace(make_trace_func('test_m1_crash_after_save', abort))
    with itest_setup(test_file_history), pytest.raises(Exception):
        backup(BACKUP_ARGS)
    assert_manifest_correct(before=False)