Browse Source

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'
patch-4
SomberNight 4 years ago
parent
commit
05fd424548
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/tests/test_storage_upgrade.py
  2. 2
      electrum/util.py

11
electrum/tests/test_storage_upgrade.py

@ -5,6 +5,7 @@ import json
from typing import Optional from typing import Optional
import asyncio import asyncio
import electrum
from electrum.wallet_db import WalletDB from electrum.wallet_db import WalletDB
from electrum.wallet import Wallet from electrum.wallet import Wallet
from electrum import constants from electrum import constants
@ -312,6 +313,8 @@ class TestStorageUpgrade(WalletTestCase):
########## ##########
plugins: 'electrum.plugin.Plugins'
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
@ -323,12 +326,14 @@ class TestStorageUpgrade(WalletTestCase):
gui_name = 'cmdline' gui_name = 'cmdline'
# TODO it's probably wasteful to load all plugins... only need Trezor # TODO it's probably wasteful to load all plugins... only need Trezor
Plugins(config, gui_name) cls.plugins = Plugins(config, gui_name)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
super().tearDownClass() super().tearDownClass()
shutil.rmtree(cls.__electrum_path) shutil.rmtree(cls.__electrum_path)
cls.plugins.stop()
cls.plugins.stopped_event.wait()
def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]: def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
if accounts == 1: if accounts == 1:
@ -358,8 +363,8 @@ class TestStorageUpgrade(WalletTestCase):
def _sanity_check_upgraded_db(self, db): def _sanity_check_upgraded_db(self, db):
self.assertFalse(db.requires_split()) self.assertFalse(db.requires_split())
self.assertFalse(db.requires_upgrade()) self.assertFalse(db.requires_upgrade())
w = Wallet(db, None, config=self.config) wallet = Wallet(db, None, config=self.config)
w.stop() asyncio.run_coroutine_threadsafe(wallet.stop(), self.asyncio_loop).result()
@staticmethod @staticmethod
def _load_db_from_json_string(*, wallet_json, manual_upgrades): def _load_db_from_json_string(*, wallet_json, manual_upgrades):

2
electrum/util.py

@ -317,6 +317,7 @@ class DaemonThread(threading.Thread, Logger):
self.running_lock = threading.Lock() self.running_lock = threading.Lock()
self.job_lock = threading.Lock() self.job_lock = threading.Lock()
self.jobs = [] self.jobs = []
self.stopped_event = threading.Event() # set when fully stopped
def add_jobs(self, jobs): def add_jobs(self, jobs):
with self.job_lock: with self.job_lock:
@ -357,6 +358,7 @@ class DaemonThread(threading.Thread, Logger):
jnius.detach() jnius.detach()
self.logger.info("jnius detach") self.logger.info("jnius detach")
self.logger.info("stopped") self.logger.info("stopped")
self.stopped_event.set()
def print_stderr(*args): def print_stderr(*args):

Loading…
Cancel
Save