tests: clean up event-loop creation
This commit is contained in:
@@ -6,6 +6,7 @@ import shutil
|
||||
import electrum
|
||||
import electrum.logging
|
||||
from electrum import constants
|
||||
from electrum import util
|
||||
|
||||
|
||||
# Set this locally to make the test suite run faster.
|
||||
@@ -37,9 +38,12 @@ class ElectrumTestCase(SequentialTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
self.electrum_path = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
shutil.rmtree(self.electrum_path)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import unittest
|
||||
from unittest import mock
|
||||
from decimal import Decimal
|
||||
|
||||
from electrum.util import create_and_start_event_loop
|
||||
from electrum.commands import Commands, eval_bool
|
||||
from electrum import storage, wallet
|
||||
from electrum.wallet import restore_wallet_from_text
|
||||
@@ -18,14 +17,8 @@ class TestCommands(ElectrumTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
|
||||
def test_setconfig_non_auth_number(self):
|
||||
self.assertEqual(7777, Commands._setconfig_normalize_value('rpcport', "7777"))
|
||||
self.assertEqual(7777, Commands._setconfig_normalize_value('rpcport', '7777'))
|
||||
@@ -135,14 +128,8 @@ class TestCommandsTestnet(TestCaseForTestnet):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
|
||||
def test_convert_xkey(self):
|
||||
cmds = Commands(config=self.config)
|
||||
xpubs = {
|
||||
|
||||
@@ -22,7 +22,7 @@ from electrum.ecc import ECPrivkey
|
||||
from electrum import simple_config, lnutil
|
||||
from electrum.lnaddr import lnencode, LnAddr, lndecode
|
||||
from electrum.bitcoin import COIN, sha256
|
||||
from electrum.util import bh2u, create_and_start_event_loop, NetworkRetryManager, bfh, OldTaskGroup
|
||||
from electrum.util import bh2u, NetworkRetryManager, bfh, OldTaskGroup
|
||||
from electrum.lnpeer import Peer
|
||||
from electrum.lnutil import LNPeerAddr, Keypair, privkey_to_pubkey
|
||||
from electrum.lnutil import PaymentFailure, LnFeatures, HTLCOwner
|
||||
@@ -369,7 +369,6 @@ class TestPeer(TestCaseForTestnet):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
|
||||
self._lnworkers_created = [] # type: List[MockLNWallet]
|
||||
|
||||
def tearDown(self):
|
||||
@@ -380,8 +379,6 @@ class TestPeer(TestCaseForTestnet):
|
||||
self._lnworkers_created.clear()
|
||||
run(cleanup_lnworkers())
|
||||
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
def prepare_peers(self, alice_channel: Channel, bob_channel: Channel):
|
||||
|
||||
@@ -5,7 +5,7 @@ import shutil
|
||||
import asyncio
|
||||
|
||||
from electrum import util
|
||||
from electrum.util import bh2u, bfh, create_and_start_event_loop
|
||||
from electrum.util import bh2u, bfh
|
||||
from electrum.lnutil import ShortChannelID
|
||||
from electrum.lnonion import (OnionHopsDataSingle, new_onion_packet,
|
||||
process_onion_packet, _decode_onion_error, decode_onion_error,
|
||||
@@ -33,7 +33,6 @@ class Test_LNRouter(TestCaseForTestnet):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
|
||||
def tearDown(self):
|
||||
@@ -41,8 +40,6 @@ class Test_LNRouter(TestCaseForTestnet):
|
||||
if self.cdb:
|
||||
self.cdb.stop()
|
||||
asyncio.run_coroutine_threadsafe(self.cdb.stopped_event.wait(), self.asyncio_loop).result()
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
def prepare_graph(self):
|
||||
|
||||
@@ -12,15 +12,6 @@ from .test_bitcoin import needs_test_with_all_chacha20_implementations
|
||||
|
||||
class TestLNTransport(ElectrumTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
@needs_test_with_all_chacha20_implementations
|
||||
def test_responder(self):
|
||||
# local static
|
||||
|
||||
@@ -55,15 +55,9 @@ class TestNetwork(ElectrumTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
self.interface = MockInterface(self.config)
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
def test_fork_noconflict(self):
|
||||
blockchain.blockchains = {}
|
||||
self.interface.q.put_nowait({'block_height': 8, 'mock': {'catchup':1, 'check': lambda x: False, 'connect': lambda x: False}})
|
||||
|
||||
@@ -18,12 +18,6 @@ from .test_wallet import WalletTestCase
|
||||
# TODO hw wallet with client version 2.6.x (single-, and multiacc)
|
||||
class TestStorageUpgrade(WalletTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
|
||||
def testnet_wallet(func):
|
||||
# note: it's ok to modify global network constants in subclasses of SequentialTestCase
|
||||
def wrapper(self, *args, **kwargs):
|
||||
|
||||
@@ -35,7 +35,6 @@ class WalletTestCase(ElectrumTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(WalletTestCase, self).setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
self.user_dir = tempfile.mkdtemp()
|
||||
self.config = SimpleConfig({'electrum_path': self.user_dir})
|
||||
|
||||
@@ -46,8 +45,6 @@ class WalletTestCase(ElectrumTestCase):
|
||||
sys.stdout = self._stdout_buffer
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super(WalletTestCase, self).tearDown()
|
||||
shutil.rmtree(self.user_dir)
|
||||
# Restore the "real" stdout
|
||||
|
||||
@@ -14,7 +14,7 @@ from electrum.address_synchronizer import TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCON
|
||||
from electrum.wallet import (sweep, Multisig_Wallet, Standard_Wallet, Imported_Wallet,
|
||||
restore_wallet_from_text, Abstract_Wallet, BumpFeeStrategy)
|
||||
from electrum.util import (
|
||||
bfh, bh2u, create_and_start_event_loop, NotEnoughFunds, UnrelatedTransactionException,
|
||||
bfh, bh2u, NotEnoughFunds, UnrelatedTransactionException,
|
||||
UserFacingException)
|
||||
from electrum.transaction import (TxOutput, Transaction, PartialTransaction, PartialTxOutput,
|
||||
PartialTxInput, tx_from_any, TxOutpoint)
|
||||
@@ -701,14 +701,8 @@ class TestWalletSending(TestCaseForTestnet):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
def create_standard_wallet_from_seed(self, seed_words, *, config=None, gap_limit=2):
|
||||
if config is None:
|
||||
config = self.config
|
||||
@@ -3271,14 +3265,8 @@ class TestWalletHistory_DoubleSpend(TestCaseForTestnet):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
|
||||
def tearDown(self):
|
||||
self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
|
||||
self._loop_thread.join(timeout=1)
|
||||
super().tearDown()
|
||||
|
||||
@mock.patch.object(wallet.Abstract_Wallet, 'save_db')
|
||||
def test_restoring_wallet_without_manual_delete(self, mock_save_db):
|
||||
w = restore_wallet_from_text("small rapid pattern language comic denial donate extend tide fever burden barrel",
|
||||
|
||||
Reference in New Issue
Block a user