1
0

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:
SomberNight
2023-09-06 14:05:45 +00:00
parent 2529323ba3
commit 4f90632b1d
2 changed files with 4 additions and 1 deletions

View File

@@ -48,6 +48,7 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase):
self._test_lock.acquire()
super().setUp()
self.electrum_path = tempfile.mkdtemp()
assert util._asyncio_event_loop is None, "global event loop already set?!"
async def asyncSetUp(self):
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
if not (os.environ.get("PYTHONASYNCIODEBUG") or os.environ.get("PYTHONDEVMODE")):
loop.set_debug(False)
util._asyncio_event_loop = loop
def tearDown(self):
shutil.rmtree(self.electrum_path)
super().tearDown()
util._asyncio_event_loop = None # cleared here, at the ~last possible moment. asyncTearDown is too early.
self._test_lock.release()

View File

@@ -326,10 +326,10 @@ class TestStorageUpgrade(WalletTestCase):
self.plugins = Plugins(config, gui_name)
def tearDown(self):
super().tearDown()
shutil.rmtree(self.__electrum_path)
self.plugins.stop()
self.plugins.stopped_event.wait()
super().tearDown()
async def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
if accounts == 1: