From 38d601619e0a9082999a7270e832c9003ac927ea Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Tue, 27 Jun 2017 14:33:47 +0200 Subject: [PATCH 1/3] archiver: add test for debug refcount-obj --- src/borg/testsuite/archiver.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 3a539eaf2..93eab20e4 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -2607,6 +2607,20 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02 assert '_meta' in result assert '_items' in result + def test_debug_refcount_obj(self): + self.cmd('init', '--encryption=repokey', self.repository_location) + output = self.cmd('debug', 'refcount-obj', self.repository_location, '0' * 64).strip() + assert output == 'object 0000000000000000000000000000000000000000000000000000000000000000 not found [info from chunks cache].' + + create_json = json.loads(self.cmd('create', '--json', self.repository_location + '::test', 'input')) + archive_id = create_json['archive']['id'] + output = self.cmd('debug', 'refcount-obj', self.repository_location, archive_id).strip() + assert output == 'object ' + archive_id + ' has 1 referrers [info from chunks cache].' + + # Invalid IDs do not abort or return an error + output = self.cmd('debug', 'refcount-obj', self.repository_location, '124', 'xyza').strip() + assert output == 'object id 124 is invalid.\nobject id xyza is invalid.' + 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.') From 5d60669c507cf4b592bdd225e518604793dca78c Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Tue, 27 Jun 2017 14:35:44 +0200 Subject: [PATCH 2/3] archiver: add test for debug info --- src/borg/testsuite/archiver.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 93eab20e4..c2e7e1d10 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -2621,6 +2621,11 @@ id: 2 / e29442 3506da 4e1ea7 / 25f62a 5a3d41 - 02 output = self.cmd('debug', 'refcount-obj', self.repository_location, '124', 'xyza').strip() assert output == 'object id 124 is invalid.\nobject id xyza is invalid.' + def test_debug_info(self): + output = self.cmd('debug', 'info') + assert 'CRC implementation' in output + assert 'Python' in output + 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.') From 4af1142693b84f6fe4a49d5b5d3291ec5dfaaa94 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Tue, 27 Jun 2017 14:47:06 +0200 Subject: [PATCH 3/3] archiver: add test_benchmark_crud, fix bug benchmark crud would just crash with a TypeError due to the missing return --- src/borg/archiver.py | 26 ++++++++++++++++++-------- src/borg/testsuite/archiver.py | 5 +++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 25b711680..64abf65d5 100644 --- a/src/borg/archiver.py +++ b/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""" diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index c2e7e1d10..5b1eedeea 100644 --- a/src/borg/testsuite/archiver.py +++ b/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.')