From 9d87de1433468a2d38d5624f1741e9108efa8370 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 13 Feb 2018 14:19:59 -0500 Subject: [PATCH] fix setup and teardown for blob manager tests --- lbrynet/tests/unit/core/test_BlobManager.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lbrynet/tests/unit/core/test_BlobManager.py b/lbrynet/tests/unit/core/test_BlobManager.py index a9194a273..3f513f623 100644 --- a/lbrynet/tests/unit/core/test_BlobManager.py +++ b/lbrynet/tests/unit/core/test_BlobManager.py @@ -3,6 +3,8 @@ import shutil import os import random import string +from twisted.trial import unittest +from twisted.internet import defer, threads from lbrynet.tests.util import random_lbry_hash from lbrynet.core.BlobManager import DiskBlobManager @@ -11,12 +13,10 @@ from lbrynet.database.storage import SQLiteStorage from lbrynet.core.Peer import Peer from lbrynet import conf from lbrynet.core.cryptoutils import get_lbry_hash_obj -from twisted.trial import unittest - -from twisted.internet import defer class BlobManagerTest(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): conf.initialize_settings() self.blob_dir = tempfile.mkdtemp() @@ -24,14 +24,17 @@ class BlobManagerTest(unittest.TestCase): hash_announcer = DummyHashAnnouncer() self.bm = DiskBlobManager(hash_announcer, self.blob_dir, SQLiteStorage(self.db_dir)) self.peer = Peer('somehost', 22) + yield self.bm.storage.setup() + @defer.inlineCallbacks def tearDown(self): - self.bm.stop() + yield self.bm.stop() + yield self.bm.storage.stop() # BlobFile will try to delete itself in _close_writer # thus when calling rmtree we may get a FileNotFoundError # for the blob file - shutil.rmtree(self.blob_dir, ignore_errors=True) - shutil.rmtree(self.db_dir) + yield threads.deferToThread(shutil.rmtree, self.blob_dir) + yield threads.deferToThread(shutil.rmtree, self.db_dir) @defer.inlineCallbacks def _create_and_add_blob(self, should_announce=False):