瀏覽代碼

archiver: add test_benchmark_crud, fix bug

benchmark crud would just crash with a TypeError due to the missing return
Marian Beermann 8 年之前
父節點
當前提交
4af1142693
共有 2 個文件被更改,包括 23 次插入8 次删除
  1. 18 8
      src/borg/archiver.py
  2. 5 0
      src/borg/testsuite/archiver.py

+ 18 - 8
src/borg/archiver.py

@@ -411,14 +411,22 @@ class Archiver:
             yield path
             shutil.rmtree(path)
 
-        for msg, count, size, random in [
-            ('Z-BIG', 10, 100000000, False),
-            ('R-BIG', 10, 100000000, True),
-            ('Z-MEDIUM', 1000, 1000000, False),
-            ('R-MEDIUM', 1000, 1000000, True),
-            ('Z-SMALL', 10000, 10000, False),
-            ('R-SMALL', 10000, 10000, True),
-        ]:
+        if '_BORG_BENCHMARK_CRUD_TEST' in os.environ:
+            tests = [
+                ('Z-TEST', 1, 1, False),
+                ('R-TEST', 1, 1, True),
+            ]
+        else:
+            tests = [
+                ('Z-BIG', 10, 100000000, False),
+                ('R-BIG', 10, 100000000, True),
+                ('Z-MEDIUM', 1000, 1000000, False),
+                ('R-MEDIUM', 1000, 1000000, True),
+                ('Z-SMALL', 10000, 10000, False),
+                ('R-SMALL', 10000, 10000, True),
+            ]
+
+        for msg, count, size, random in tests:
             with test_files(args.path, count, size, random) as path:
                 dt_create, dt_update, dt_extract, dt_delete = measurement_run(args.location.canonical_path(), path)
             total_size_MB = count * size / 1e06
@@ -430,6 +438,8 @@ class Archiver:
             print(fmt % ('U', msg, total_size_MB / dt_update, count, file_size_formatted, content, dt_update))
             print(fmt % ('D', msg, total_size_MB / dt_delete, count, file_size_formatted, content, dt_delete))
 
+        return 0
+
     @with_repository(fake='dry_run', exclusive=True, compatibility=(Manifest.Operation.WRITE,))
     def do_create(self, args, repository, manifest=None, key=None):
         """Create new archive"""

+ 5 - 0
src/borg/testsuite/archiver.py

@@ -2626,6 +2626,11 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02
         assert 'CRC implementation' in output
         assert 'Python' in output
 
+    def test_benchmark_crud(self):
+        self.cmd('init', '--encryption=repokey', self.repository_location)
+        with environment_variable(_BORG_BENCHMARK_CRUD_TEST='YES'):
+            self.cmd('benchmark', 'crud', self.repository_location, self.input_path)
+
     requires_gnutar = pytest.mark.skipif(not have_gnutar(), reason='GNU tar must be installed for this test.')
     requires_gzip = pytest.mark.skipif(not shutil.which('gzip'), reason='gzip must be installed for this test.')