diff --git a/tests/unit/core/test_HashBlob.py b/tests/unit/core/test_HashBlob.py index d1c282478..93a19ef19 100644 --- a/tests/unit/core/test_HashBlob.py +++ b/tests/unit/core/test_HashBlob.py @@ -44,9 +44,15 @@ class BlobFileTest(unittest.TestCase): blob_file = BlobFile(self.blob_dir, self.fake_content_hash, self.fake_content_len) self.assertTrue(blob_file.verified) f = blob_file.open_for_reading() + self.assertEqual(1, blob_file.readers) c = f.read() self.assertEqual(c, self.fake_content) + # close reader + f.close() + self.assertEqual(0, blob_file.readers) + + @defer.inlineCallbacks def test_delete(self): blob_file = BlobFile(self.blob_dir, self.fake_content_hash, self.fake_content_len) @@ -58,6 +64,21 @@ class BlobFileTest(unittest.TestCase): blob_file = BlobFile(self.blob_dir, self.fake_content_hash) self.assertFalse(blob_file.verified) + @defer.inlineCallbacks + def test_delete_fail(self): + # deletes should fail if being written to + blob_file = BlobFile(self.blob_dir, self.fake_content_hash, self.fake_content_len) + writer, finished_d = blob_file.open_for_writing(peer=1) + yield self.assertFailure(blob_file.delete(), ValueError) + writer.write(self.fake_content) + writer.close() + + # deletes should fail if being read and not closed + blob_file = BlobFile(self.blob_dir, self.fake_content_hash, self.fake_content_len) + self.assertTrue(blob_file.verified) + f = blob_file.open_for_reading() + yield self.assertFailure(blob_file.delete(), ValueError) + @defer.inlineCallbacks def test_too_much_write(self): # writing too much data should result in failure