fix setup and teardown for blob manager tests

This commit is contained in:
Jack Robison 2018-02-13 14:19:59 -05:00
parent 3769287e88
commit 9d87de1433
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -3,6 +3,8 @@ import shutil
import os import os
import random import random
import string import string
from twisted.trial import unittest
from twisted.internet import defer, threads
from lbrynet.tests.util import random_lbry_hash from lbrynet.tests.util import random_lbry_hash
from lbrynet.core.BlobManager import DiskBlobManager from lbrynet.core.BlobManager import DiskBlobManager
@ -11,12 +13,10 @@ from lbrynet.database.storage import SQLiteStorage
from lbrynet.core.Peer import Peer from lbrynet.core.Peer import Peer
from lbrynet import conf from lbrynet import conf
from lbrynet.core.cryptoutils import get_lbry_hash_obj from lbrynet.core.cryptoutils import get_lbry_hash_obj
from twisted.trial import unittest
from twisted.internet import defer
class BlobManagerTest(unittest.TestCase): class BlobManagerTest(unittest.TestCase):
@defer.inlineCallbacks
def setUp(self): def setUp(self):
conf.initialize_settings() conf.initialize_settings()
self.blob_dir = tempfile.mkdtemp() self.blob_dir = tempfile.mkdtemp()
@ -24,14 +24,17 @@ class BlobManagerTest(unittest.TestCase):
hash_announcer = DummyHashAnnouncer() hash_announcer = DummyHashAnnouncer()
self.bm = DiskBlobManager(hash_announcer, self.blob_dir, SQLiteStorage(self.db_dir)) self.bm = DiskBlobManager(hash_announcer, self.blob_dir, SQLiteStorage(self.db_dir))
self.peer = Peer('somehost', 22) self.peer = Peer('somehost', 22)
yield self.bm.storage.setup()
@defer.inlineCallbacks
def tearDown(self): def tearDown(self):
self.bm.stop() yield self.bm.stop()
yield self.bm.storage.stop()
# BlobFile will try to delete itself in _close_writer # BlobFile will try to delete itself in _close_writer
# thus when calling rmtree we may get a FileNotFoundError # thus when calling rmtree we may get a FileNotFoundError
# for the blob file # for the blob file
shutil.rmtree(self.blob_dir, ignore_errors=True) yield threads.deferToThread(shutil.rmtree, self.blob_dir)
shutil.rmtree(self.db_dir) yield threads.deferToThread(shutil.rmtree, self.db_dir)
@defer.inlineCallbacks @defer.inlineCallbacks
def _create_and_add_blob(self, should_announce=False): def _create_and_add_blob(self, should_announce=False):