commit 05fd42454842bdce853e96d6b3ffbb043960f7c4
parent 5339e0054c6e473ec4b5858ea9bb11aeb37be109
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 10 Mar 2021 20:16:25 +0100
tests: maybe fix tearDown() issue in test_storage_upgrade.py
from travis logs:
--- Logging error ---
Traceback (most recent call last):
File "/opt/python/3.7.6/lib/python3.7/logging/__init__.py", line 1028, in emit
stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 890, in _bootstrap
self._bootstrap_inner()
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/travis/build/spesmilo/electrum/electrum/plugin.py", line 213, in run
self.run_jobs()
File "/home/travis/build/spesmilo/electrum/electrum/util.py", line 359, in on_stop
self.logger.info("stopped")
Message: 'stopped'
Diffstat:
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/electrum/tests/test_storage_upgrade.py b/electrum/tests/test_storage_upgrade.py
@@ -5,6 +5,7 @@ import json
from typing import Optional
import asyncio
+import electrum
from electrum.wallet_db import WalletDB
from electrum.wallet import Wallet
from electrum import constants
@@ -312,6 +313,8 @@ class TestStorageUpgrade(WalletTestCase):
##########
+ plugins: 'electrum.plugin.Plugins'
+
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -323,12 +326,14 @@ class TestStorageUpgrade(WalletTestCase):
gui_name = 'cmdline'
# TODO it's probably wasteful to load all plugins... only need Trezor
- Plugins(config, gui_name)
+ cls.plugins = Plugins(config, gui_name)
@classmethod
def tearDownClass(cls):
super().tearDownClass()
shutil.rmtree(cls.__electrum_path)
+ cls.plugins.stop()
+ cls.plugins.stopped_event.wait()
def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
if accounts == 1:
@@ -358,8 +363,8 @@ class TestStorageUpgrade(WalletTestCase):
def _sanity_check_upgraded_db(self, db):
self.assertFalse(db.requires_split())
self.assertFalse(db.requires_upgrade())
- w = Wallet(db, None, config=self.config)
- w.stop()
+ wallet = Wallet(db, None, config=self.config)
+ asyncio.run_coroutine_threadsafe(wallet.stop(), self.asyncio_loop).result()
@staticmethod
def _load_db_from_json_string(*, wallet_json, manual_upgrades):
diff --git a/electrum/util.py b/electrum/util.py
@@ -317,6 +317,7 @@ class DaemonThread(threading.Thread, Logger):
self.running_lock = threading.Lock()
self.job_lock = threading.Lock()
self.jobs = []
+ self.stopped_event = threading.Event() # set when fully stopped
def add_jobs(self, jobs):
with self.job_lock:
@@ -357,6 +358,7 @@ class DaemonThread(threading.Thread, Logger):
jnius.detach()
self.logger.info("jnius detach")
self.logger.info("stopped")
+ self.stopped_event.set()
def print_stderr(*args):