From 5e470007f072fc44b17b180c3352f4f6274c69b9 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 22 Apr 2016 01:20:47 +0200 Subject: [PATCH] ChunkBuffer: add test for leaving partial chunk in buffer --- borg/testsuite/archive.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/borg/testsuite/archive.py b/borg/testsuite/archive.py index fc9a970ca..e9722cf22 100644 --- a/borg/testsuite/archive.py +++ b/borg/testsuite/archive.py @@ -57,6 +57,27 @@ def test(self): unpacker.feed(cache.objects[id]) self.assert_equal(data, list(unpacker)) + def test_partial(self): + big = b"0123456789" * 10000 + data = [{b'full': 1, b'data': big}, {b'partial': 2, b'data': big}] + cache = MockCache() + key = PlaintextKey(None) + chunks = CacheChunkBuffer(cache, key, None) + for d in data: + chunks.add(d) + chunks.flush(flush=False) + # the code is expected to leave the last partial chunk in the buffer + self.assert_equal(len(chunks.chunks), 3) + self.assert_true(chunks.buffer.tell() > 0) + # now really flush + chunks.flush(flush=True) + self.assert_equal(len(chunks.chunks), 4) + self.assert_true(chunks.buffer.tell() == 0) + unpacker = msgpack.Unpacker() + for id in chunks.chunks: + unpacker.feed(cache.objects[id]) + self.assert_equal(data, list(unpacker)) + class RobustUnpackerTestCase(BaseTestCase):