Browse Source

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().
master
SomberNight 2 years ago
parent
commit
4f90632b1d
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/tests/__init__.py
  2. 2
      electrum/tests/test_storage_upgrade.py

3
electrum/tests/__init__.py

@ -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()

2
electrum/tests/test_storage_upgrade.py

@ -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:

Loading…
Cancel
Save