Add test when mutliple writers call _save_verified_blob at once, this will cause deadlock

This commit is contained in:
Kay Kurokawa 2017-10-06 16:34:45 -04:00
parent d1511cba54
commit 2115919c55
No known key found for this signature in database
GPG key ID: 2D65FB1698958B8D

View file

@ -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.trial import unittest
from twisted.internet import defer from twisted.internet import defer
class BlobFileTest(unittest.TestCase): class BlobFileTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.db_dir, self.blob_dir = mk_db_and_blob_dir() 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(self.fake_content_len, len(c))
self.assertEqual(bytearray(c), self.fake_content) 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)