fix memory blob showing as completed/verified

This commit is contained in:
Victor Shyba 2019-07-17 02:49:08 -03:00
parent 8b1307e1ca
commit 4d64fca9de
2 changed files with 14 additions and 2 deletions

View file

@ -69,10 +69,10 @@ class BlobManager:
def is_blob_verified(self, blob_hash: str, length: typing.Optional[int] = None) -> bool: def is_blob_verified(self, blob_hash: str, length: typing.Optional[int] = None) -> bool:
if not is_valid_blobhash(blob_hash): if not is_valid_blobhash(blob_hash):
raise ValueError(blob_hash) raise ValueError(blob_hash)
if blob_hash in self.blobs:
return self.blobs[blob_hash].get_is_verified()
if not os.path.isfile(os.path.join(self.blob_dir, blob_hash)): if not os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
return False return False
if blob_hash in self.blobs:
return self.blobs[blob_hash].get_is_verified()
return self._get_blob(blob_hash, length).get_is_verified() return self._get_blob(blob_hash, length).get_is_verified()
async def setup(self) -> bool: async def setup(self) -> bool:

View file

@ -17,6 +17,18 @@ class TestBlobManager(AsyncioTestCase):
self.blob_manager = BlobManager(self.loop, tmp_dir, self.storage, self.config) self.blob_manager = BlobManager(self.loop, tmp_dir, self.storage, self.config)
await self.storage.open() await self.storage.open()
async def test_memory_blobs_arent_verifie_but_real_ones_are(self):
for save_blobs in (False, True):
await self.setup_blob_manager(save_blobs=save_blobs)
# add a blob file
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
blob_bytes = b'1' * ((2 * 2 ** 20) - 1)
blob = self.blob_manager.get_blob(blob_hash, len(blob_bytes))
blob.save_verified_blob(blob_bytes)
self.assertTrue(blob.get_is_verified())
self.blob_manager.blob_completed(blob)
self.assertEqual(self.blob_manager.is_blob_verified(blob_hash), save_blobs)
async def test_sync_blob_file_manager_on_startup(self): async def test_sync_blob_file_manager_on_startup(self):
await self.setup_blob_manager(save_blobs=True) await self.setup_blob_manager(save_blobs=True)