mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-11 09:59:19 -04:00
Merge pull request #8862 from ThomasWaldmann/tests-save-temp-space
Tests: save temp space
This commit is contained in:
commit
dc7d876957
6 changed files with 18 additions and 8 deletions
|
|
@ -204,11 +204,11 @@ def test_sparse_file(archivers, request):
|
|||
sparse = False
|
||||
return sparse
|
||||
|
||||
filename = os.path.join(archiver.input_path, "sparse")
|
||||
filename_in = os.path.join(archiver.input_path, "sparse")
|
||||
content = b"foobar"
|
||||
hole_size = 5 * (1 << CHUNK_MAX_EXP) # 5 full chunker buffers
|
||||
total_size = hole_size + len(content) + hole_size
|
||||
with open(filename, "wb") as fd:
|
||||
with open(filename_in, "wb") as fd:
|
||||
# create a file that has a hole at the beginning and end (if the
|
||||
# OS and filesystem supports sparse files)
|
||||
fd.seek(hole_size, 1)
|
||||
|
|
@ -217,7 +217,7 @@ def test_sparse_file(archivers, request):
|
|||
pos = fd.tell()
|
||||
fd.truncate(pos)
|
||||
# we first check if we could create a sparse input file:
|
||||
sparse_support = is_sparse(filename, total_size, hole_size)
|
||||
sparse_support = is_sparse(filename_in, total_size, hole_size)
|
||||
if sparse_support:
|
||||
# we could create a sparse input file, so creating a backup of it and
|
||||
# extracting it again (as sparse) should also work:
|
||||
|
|
@ -226,13 +226,15 @@ def test_sparse_file(archivers, request):
|
|||
with changedir(archiver.output_path):
|
||||
cmd(archiver, "extract", "test", "--sparse")
|
||||
assert_dirs_equal("input", "output/input")
|
||||
filename = os.path.join(archiver.output_path, "input", "sparse")
|
||||
with open(filename, "rb") as fd:
|
||||
filename_out = os.path.join(archiver.output_path, "input", "sparse")
|
||||
with open(filename_out, "rb") as fd:
|
||||
# check if file contents are as expected
|
||||
assert fd.read(hole_size) == b"\0" * hole_size
|
||||
assert fd.read(len(content)) == content
|
||||
assert fd.read(hole_size) == b"\0" * hole_size
|
||||
assert is_sparse(filename, total_size, hole_size)
|
||||
assert is_sparse(filename_out, total_size, hole_size)
|
||||
os.unlink(filename_out) # save space on TMPDIR
|
||||
os.unlink(filename_in) # save space on TMPDIR
|
||||
|
||||
|
||||
def test_unusual_filenames(archivers, request):
|
||||
|
|
|
|||
|
|
@ -35,11 +35,13 @@ def test_list_chunk_counts(archivers, request):
|
|||
archiver = request.getfixturevalue(archivers)
|
||||
create_regular_file(archiver.input_path, "empty_file", size=0)
|
||||
create_regular_file(archiver.input_path, "two_chunks")
|
||||
with open(os.path.join(archiver.input_path, "two_chunks"), "wb") as fd:
|
||||
filename = os.path.join(archiver.input_path, "two_chunks")
|
||||
with open(filename, "wb") as fd:
|
||||
fd.write(b"abba" * 2000000)
|
||||
fd.write(b"baab" * 2000000)
|
||||
cmd(archiver, "repo-create", RK_ENCRYPTION)
|
||||
cmd(archiver, "create", "test", "input")
|
||||
os.unlink(filename) # save space on TMPDIR
|
||||
output = cmd(archiver, "list", "test", "--format", "{num_chunks} {path}{NL}")
|
||||
assert "0 input/empty_file" in output
|
||||
assert "2 input/two_chunks" in output
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ def test_repo_space_modify_reservation(archivers, request):
|
|||
|
||||
# note: --reserve can only INCREASE the amount of reserved space.
|
||||
|
||||
cmd(archiver, "repo-space", "--free") # save space on TMPDIR
|
||||
|
||||
|
||||
def test_repo_space_edge_cases(archivers, request):
|
||||
archiver = request.getfixturevalue(archivers)
|
||||
|
|
@ -78,3 +80,5 @@ def test_repo_space_edge_cases(archivers, request):
|
|||
# Check that space is reserved (should be 64MiB).
|
||||
output = cmd(archiver, "repo-space")
|
||||
assert "There is 67.11 MB reserved space in this repository." in output
|
||||
|
||||
cmd(archiver, "repo-space", "--free") # save space on TMPDIR
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ def test_transfer_rechunk(archivers, request, monkeypatch):
|
|||
"""Test transfer with re-chunking"""
|
||||
archiver = request.getfixturevalue(archivers)
|
||||
|
||||
BLKSIZE = 4096
|
||||
BLKSIZE = 512
|
||||
source_chunker_params = "buzhash,19,23,21,4095" # default buzhash chunks
|
||||
dest_chunker_params = f"fixed,{BLKSIZE}" # fixed chunk size
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ def test_max_data_size(repo_fixtures, request):
|
|||
assert pdchunk(repository.get(H(0))) == max_data
|
||||
with pytest.raises(IntegrityError):
|
||||
repository.put(H(1), fchunk(max_data + b"x"))
|
||||
repository.delete(H(0))
|
||||
|
||||
|
||||
def _assert_sparse(repository):
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ def test_max_data_size(repo_fixtures, request):
|
|||
assert pdchunk(repository.get(H(0))) == max_data
|
||||
with pytest.raises(IntegrityError):
|
||||
repository.put(H(1), fchunk(max_data + b"x"))
|
||||
repository.delete(H(0))
|
||||
|
||||
|
||||
def check(repository, repo_path, repair=False, status=True):
|
||||
|
|
|
|||
Loading…
Reference in a new issue