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:
parent
035a884f1e
commit
5e470007f0
1 changed files with 21 additions and 0 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Reference in a new issue