refactor: deduplicate threads array

This commit is contained in:
tecnovert
2025-10-15 18:12:24 +02:00
parent 3794b58021
commit 19fd15b9dc
6 changed files with 56 additions and 114 deletions

View File

@@ -42,9 +42,6 @@ from basicswap.basicswap_util import (
from basicswap.util.address import (
toWIF,
)
from basicswap.http_server import (
HttpThread,
)
from tests.basicswap.util import (
read_json_api,
)
@@ -58,7 +55,6 @@ from tests.basicswap.common import (
wait_for_unspent,
wait_for_bid_tx_state,
wait_for_in_progress,
TEST_HTTP_HOST,
TEST_HTTP_PORT,
BASE_PORT,
BASE_RPC_PORT,
@@ -306,7 +302,6 @@ class Test(unittest.TestCase):
cls.daemons = []
cls.swap_clients = []
cls.http_threads = []
btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE))
if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, "bitcoin-wallet")):
@@ -417,10 +412,6 @@ class Test(unittest.TestCase):
sc.start()
t = HttpThread(TEST_HTTP_HOST, TEST_HTTP_PORT + i, False, sc)
cls.http_threads.append(t)
t.start()
waitForRPC(dashRpc, delay_event)
num_blocks = 500
logging.info("Mining %d dash blocks", num_blocks)
@@ -473,15 +464,11 @@ class Test(unittest.TestCase):
stop_test = True
cls.update_thread.join()
cls.coins_update_thread.join()
for t in cls.http_threads:
t.stop()
t.join()
for c in cls.swap_clients:
c.finalise()
stopDaemons(cls.daemons)
cls.http_threads.clear()
cls.swap_clients.clear()
cls.daemons.clear()

View File

@@ -35,9 +35,6 @@ from basicswap.util.address import (
from basicswap.rpc import (
callrpc,
)
from basicswap.http_server import (
HttpThread,
)
from tests.basicswap.util import (
read_json_api,
)
@@ -84,7 +81,7 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey):
"p2p_port": BASE_P2P_PORT + node_id,
"zmqhost": "tcp://127.0.0.1",
"zmqport": BASE_ZMQ_PORT + node_id,
"htmlhost": "127.0.0.1",
"htmlhost": TEST_HTTP_HOST,
"htmlport": TEST_HTTP_PORT + node_id,
"network_key": network_key,
"network_pubkey": network_pubkey,
@@ -185,7 +182,6 @@ class Test(unittest.TestCase):
cls.update_thread = None
cls.coins_update_thread = None
cls.http_threads = []
cls.swap_clients = []
cls.part_daemons = []
cls.btc_daemons = []
@@ -334,10 +330,6 @@ class Test(unittest.TestCase):
sc.setDaemonPID(Coins.PART, cls.part_daemons[i].handle.pid)
sc.start()
t = HttpThread(TEST_HTTP_HOST, TEST_HTTP_PORT + i, False, sc)
cls.http_threads.append(t)
t.start()
cls.btc_addr = callnoderpc(
0,
"getnewaddress",
@@ -388,9 +380,6 @@ class Test(unittest.TestCase):
except Exception:
logging.info("Failed to join coins_update_thread")
for t in cls.http_threads:
t.stop()
t.join()
for c in cls.swap_clients:
c.finalise()
@@ -399,7 +388,6 @@ class Test(unittest.TestCase):
cls.part_daemons.clear()
cls.btc_daemons.clear()
cls.http_threads.clear()
cls.swap_clients.clear()
super(Test, cls).tearDownClass()

View File

@@ -42,9 +42,6 @@ from basicswap.basicswap_util import (
from basicswap.util.address import (
toWIF,
)
from basicswap.http_server import (
HttpThread,
)
from tests.basicswap.util import (
read_json_api,
)
@@ -58,7 +55,6 @@ from tests.basicswap.common import (
wait_for_unspent,
wait_for_in_progress,
wait_for_bid_tx_state,
TEST_HTTP_HOST,
TEST_HTTP_PORT,
BASE_PORT,
BASE_RPC_PORT,
@@ -318,7 +314,6 @@ class Test(unittest.TestCase):
cls.daemons = []
cls.swap_clients = []
cls.http_threads = []
btc_data_dir = os.path.join(cfg.TEST_DATADIRS, str(BTC_NODE))
if os.path.exists(os.path.join(cfg.BITCOIN_BINDIR, "bitcoin-wallet")):
@@ -418,10 +413,6 @@ class Test(unittest.TestCase):
sc.setDaemonPID(Coins.PART, cls.daemons[2 + i].handle.pid)
sc.start()
t = HttpThread(TEST_HTTP_HOST, TEST_HTTP_PORT + i, False, sc)
cls.http_threads.append(t)
t.start()
waitForRPC(pivxRpc, delay_event)
num_blocks = 1352 # CHECKLOCKTIMEVERIFY soft-fork activates at (regtest) block height 1351.
logging.info("Mining %d pivx blocks", num_blocks)
@@ -471,14 +462,10 @@ class Test(unittest.TestCase):
stop_test = True
cls.update_thread.join()
cls.coins_update_thread.join()
for t in cls.http_threads:
t.stop()
t.join()
for c in cls.swap_clients:
c.finalise()
stopDaemons(cls.daemons)
cls.http_threads.clear()
cls.swap_clients.clear()
cls.daemons.clear()

View File

@@ -50,9 +50,6 @@ from basicswap.rpc_xmr import (
from basicswap.interface.xmr import (
XMR_COIN,
)
from basicswap.http_server import (
HttpThread,
)
from tests.basicswap.util import (
make_boolean,
post_json_req,
@@ -151,7 +148,7 @@ def prepare_swapclient_dir(
"debug": True,
"zmqhost": "tcp://127.0.0.1",
"zmqport": BASE_ZMQ_PORT + node_id,
"htmlhost": "127.0.0.1",
"htmlhost": TEST_HTTP_HOST,
"htmlport": TEST_HTTP_PORT + node_id,
"network_key": network_key,
"network_pubkey": network_pubkey,
@@ -320,7 +317,6 @@ class BaseTest(unittest.TestCase):
__test__ = False
update_thread = None
coins_update_thread = None
http_threads = []
swap_clients = []
part_daemons = []
btc_daemons = []
@@ -707,9 +703,6 @@ class BaseTest(unittest.TestCase):
# Import a random seed to keep the existing test behaviour. BTC core rescans even with timestamp: now.
sc.ci(Coins.BTC).initialiseWallet(random.randbytes(32))
t = HttpThread(TEST_HTTP_HOST, TEST_HTTP_PORT + i, False, sc)
cls.http_threads.append(t)
t.start()
# Set future block rewards to nowhere (a random address), so wallet amounts stay constant
void_block_rewards_pubkey = cls.getRandomPubkey()
if cls.restore_instance:
@@ -969,9 +962,6 @@ class BaseTest(unittest.TestCase):
cls.coins_update_thread.join()
except Exception:
logging.info("Failed to join coins_update_thread")
for t in cls.http_threads:
t.stop()
t.join()
logging.info("Stopping swap clients")
for c in cls.swap_clients:
c.finalise()
@@ -982,7 +972,6 @@ class BaseTest(unittest.TestCase):
stopDaemons(cls.btc_daemons)
stopDaemons(cls.ltc_daemons)
cls.http_threads.clear()
cls.swap_clients.clear()
cls.part_daemons.clear()
cls.btc_daemons.clear()