From 2115919c551e073b1f0781eacc0b0f01258eb2d7 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 6 Oct 2017 16:34:45 -0400 Subject: [PATCH] Add test when mutliple writers call _save_verified_blob at once, this will cause deadlock --- lbrynet/tests/unit/core/test_HashBlob.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lbrynet/tests/unit/core/test_HashBlob.py b/lbrynet/tests/unit/core/test_HashBlob.py index 925414067..888887bb8 100644 --- a/lbrynet/tests/unit/core/test_HashBlob.py +++ b/lbrynet/tests/unit/core/test_HashBlob.py @@ -6,7 +6,6 @@ from lbrynet.tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir, random_lb from twisted.trial import unittest from twisted.internet import defer - class BlobFileTest(unittest.TestCase): def setUp(self): self.db_dir, self.blob_dir = mk_db_and_blob_dir() @@ -144,4 +143,14 @@ class BlobFileTest(unittest.TestCase): self.assertEqual(self.fake_content_len, len(c)) self.assertEqual(bytearray(c), self.fake_content) + @defer.inlineCallbacks + def test_multiple_writers_save_at_same_time(self): + blob_hash = self.fake_content_hash + blob_file = BlobFile(self.blob_dir, blob_hash, self.fake_content_len) + writer_1, finished_d_1 = blob_file.open_for_writing(peer=1) + writer_2, finished_d_2 = blob_file.open_for_writing(peer=2) + + blob_file._save_verified_blob(writer_1) + # second write should fail to save + yield self.assertFailure(blob_file._save_verified_blob(writer_2), DownloadCanceledError)