From 4f90632b1d4cba71b518b1d94f3128e82a350e8a Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 6 Sep 2023 14:05:45 +0000 Subject: [PATCH] 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(). --- electrum/tests/__init__.py | 3 +++ electrum/tests/test_storage_upgrade.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/electrum/tests/__init__.py b/electrum/tests/__init__.py index 6ef060e7d..64210a976 100644 --- a/electrum/tests/__init__.py +++ b/electrum/tests/__init__.py @@ -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() diff --git a/electrum/tests/test_storage_upgrade.py b/electrum/tests/test_storage_upgrade.py index 21ed8369e..0f7e10d87 100644 --- a/electrum/tests/test_storage_upgrade.py +++ b/electrum/tests/test_storage_upgrade.py @@ -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: