test that corrupted sd blobs gets delete if fails to decode

This commit is contained in:
Victor Shyba 2019-02-21 20:53:04 -03:00
parent 4e7d88311f
commit edb5083a5e

View file

@ -109,14 +109,17 @@ class TestRecoverOldStreamDescriptors(AsyncioTestCase):
self.assertEqual(sd_hash, descriptor.calculate_old_sort_sd_hash()) self.assertEqual(sd_hash, descriptor.calculate_old_sort_sd_hash())
self.assertNotEqual(sd_hash, descriptor.calculate_sd_hash()) self.assertNotEqual(sd_hash, descriptor.calculate_sd_hash())
async def test_decode_corrupt_blob_raises_proper_exception(self): async def test_decode_corrupt_blob_raises_proper_exception_and_deletes_corrupt_file(self):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
tmp_dir = tempfile.mkdtemp() tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp_dir)) self.addCleanup(lambda: shutil.rmtree(tmp_dir))
sd_hash = '9313d1807551186126acc3662e74d9de29cede78d4f133349ace846273ef116b9bb86be86c54509eb84840e4b032f6b2' sd_hash = '9313d1807551186126acc3662e74d9de29cede78d4f133349ace846273ef116b9bb86be86c54509eb84840e4b032f6b2'
with open(os.path.join(tmp_dir, sd_hash), 'wb') as handle: with open(os.path.join(tmp_dir, sd_hash), 'wb') as handle:
handle.write(b'doesnt work') handle.write(b'doesnt work')
blob = BlobFile(loop, tmp_dir, sd_hash)
self.assertTrue(blob.file_exists)
with self.assertRaises(InvalidStreamDescriptorError): with self.assertRaises(InvalidStreamDescriptorError):
await StreamDescriptor.from_stream_descriptor_blob( await StreamDescriptor.from_stream_descriptor_blob(
loop, tmp_dir, BlobFile(loop, tmp_dir, sd_hash) loop, tmp_dir, BlobFile(loop, tmp_dir, sd_hash)
) )
self.assertFalse(blob.file_exists)