1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-23 22:51:35 +00:00

ChunkBuffer: add test for leaving partial chunk in buffer

This commit is contained in:
Thomas Waldmann 2016-04-22 01:20:47 +02:00
parent 035a884f1e
commit 5e470007f0

View file

@ -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):