1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-04 06:21:46 +00:00

benchmark crud: use TemporaryDirectory below given path, fixes #4706

This commit is contained in:
Thomas Waldmann 2023-04-07 18:05:19 +02:00
parent 09781e1d30
commit 08a2db9410
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -2,7 +2,7 @@
from contextlib import contextmanager from contextlib import contextmanager
import functools import functools
import os import os
import shutil import tempfile
import time import time
from ..constants import * # NOQA from ..constants import * # NOQA
@ -60,9 +60,7 @@ def measurement_run(repo, path):
@contextmanager @contextmanager
def test_files(path, count, size, random): def test_files(path, count, size, random):
try: with tempfile.TemporaryDirectory(prefix="borg-test-data-", dir=path) as path:
path = os.path.join(path, "borg-test-data")
os.makedirs(path)
z_buff = None if random else memoryview(zeros)[:size] if size <= len(zeros) else b"\0" * size z_buff = None if random else memoryview(zeros)[:size] if size <= len(zeros) else b"\0" * size
for i in range(count): for i in range(count):
fname = os.path.join(path, "file_%d" % i) fname = os.path.join(path, "file_%d" % i)
@ -70,8 +68,6 @@ def test_files(path, count, size, random):
with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake
fd.write(data) fd.write(data)
yield path yield path
finally:
shutil.rmtree(path)
if "_BORG_BENCHMARK_CRUD_TEST" in os.environ: if "_BORG_BENCHMARK_CRUD_TEST" in os.environ:
tests = [("Z-TEST", 1, 1, False), ("R-TEST", 1, 1, True)] tests = [("Z-TEST", 1, 1, False), ("R-TEST", 1, 1, True)]