tests: fix warnings in test_storage_upgrade.py
Manage global event loop so that it is accessible to threads other than the asyncio thread. In particular, the Plugins thread needs to reference it in its on_stop().
This commit is contained in:
@@ -48,6 +48,7 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase):
|
|||||||
self._test_lock.acquire()
|
self._test_lock.acquire()
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.electrum_path = tempfile.mkdtemp()
|
self.electrum_path = tempfile.mkdtemp()
|
||||||
|
assert util._asyncio_event_loop is None, "global event loop already set?!"
|
||||||
|
|
||||||
async def asyncSetUp(self):
|
async def asyncSetUp(self):
|
||||||
await super().asyncSetUp()
|
await super().asyncSetUp()
|
||||||
@@ -55,10 +56,12 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase):
|
|||||||
# IsolatedAsyncioTestCase creates event loops with debug=True, which makes the tests take ~4x time
|
# IsolatedAsyncioTestCase creates event loops with debug=True, which makes the tests take ~4x time
|
||||||
if not (os.environ.get("PYTHONASYNCIODEBUG") or os.environ.get("PYTHONDEVMODE")):
|
if not (os.environ.get("PYTHONASYNCIODEBUG") or os.environ.get("PYTHONDEVMODE")):
|
||||||
loop.set_debug(False)
|
loop.set_debug(False)
|
||||||
|
util._asyncio_event_loop = loop
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.electrum_path)
|
shutil.rmtree(self.electrum_path)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
util._asyncio_event_loop = None # cleared here, at the ~last possible moment. asyncTearDown is too early.
|
||||||
self._test_lock.release()
|
self._test_lock.release()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -326,10 +326,10 @@ class TestStorageUpgrade(WalletTestCase):
|
|||||||
self.plugins = Plugins(config, gui_name)
|
self.plugins = Plugins(config, gui_name)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
|
||||||
shutil.rmtree(self.__electrum_path)
|
shutil.rmtree(self.__electrum_path)
|
||||||
self.plugins.stop()
|
self.plugins.stop()
|
||||||
self.plugins.stopped_event.wait()
|
self.plugins.stopped_event.wait()
|
||||||
|
super().tearDown()
|
||||||
|
|
||||||
async def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
|
async def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
|
||||||
if accounts == 1:
|
if accounts == 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user