From d9bd57c1cf8e8421f854e4139134838ba129d0c3 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 2 Sep 2024 09:43:47 +0000 Subject: [PATCH] test suite autosign: refactor wait loop thread --- test/cmdtest_py_d/ct_automount.py | 4 ++-- test/cmdtest_py_d/ct_automount_eth.py | 4 ++-- test/cmdtest_py_d/ct_autosign.py | 27 ++++++++++++++------------- test/cmdtest_py_d/ct_xmr_autosign.py | 4 ++-- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/test/cmdtest_py_d/ct_automount.py b/test/cmdtest_py_d/ct_automount.py index c818a831..b72a08d4 100755 --- a/test/cmdtest_py_d/ct_automount.py +++ b/test/cmdtest_py_d/ct_automount.py @@ -43,7 +43,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) ('alice_txcreate_bad_have_unsigned', 'creating the transaction again (error)'), ('copy_wallet', 'copying Alice’s wallet'), ('alice_run_autosign_setup', 'running ‘autosign setup’ (with default wallet)'), - ('autosign_start_thread', 'starting autosign wait loop'), + ('wait_loop_start', 'starting autosign wait loop'), ('alice_txstatus1', 'getting transaction status (unsigned)'), ('alice_txstatus2', 'getting transaction status (unsent)'), ('alice_txcreate_bad_have_unsent', 'creating the transaction again (error)'), @@ -66,7 +66,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) ('alice_txsend2', 'sending the transaction'), ('alice_txbump3', 'bumping the transaction'), ('alice_txsend3', 'sending the bumped transaction'), - ('autosign_kill_thread', 'stopping autosign wait loop'), + ('wait_loop_kill', 'stopping autosign wait loop'), ('stop', 'stopping regtest daemon'), ('txview', 'viewing transactions'), ) diff --git a/test/cmdtest_py_d/ct_automount_eth.py b/test/cmdtest_py_d/ct_automount_eth.py index c616cc38..7619cbc1 100755 --- a/test/cmdtest_py_d/ct_automount_eth.py +++ b/test/cmdtest_py_d/ct_automount_eth.py @@ -33,7 +33,7 @@ class CmdTestAutosignETH(CmdTestAutosignThreaded, CmdTestEthdev): ('fund_mmgen_address', 'funding an MMGen address'), ('create_tx', 'creating a transaction'), ('run_autosign_setup', 'running ‘autosign setup’'), - ('autosign_start_thread', 'starting autosign wait loop'), + ('wait_loop_start', 'starting autosign wait loop'), ('send_tx', 'sending the transaction'), ('token_compile1', 'compiling ERC20 token #1'), ('token_deploy1a', 'deploying ERC20 token #1 (SafeMath)'), @@ -47,7 +47,7 @@ class CmdTestAutosignETH(CmdTestAutosignThreaded, CmdTestEthdev): ('create_token_tx', 'creating a token transaction'), ('send_token_tx', 'sending a token transaction'), ('token_bal2', f'the {cfg.coin} balance and token balance'), - ('autosign_kill_thread', 'stopping autosign wait loop'), + ('wait_loop_kill', 'stopping autosign wait loop'), ('stop', 'stopping daemon'), ('txview', 'viewing transactions'), ) diff --git a/test/cmdtest_py_d/ct_autosign.py b/test/cmdtest_py_d/ct_autosign.py index e60d2118..7338c36f 100755 --- a/test/cmdtest_py_d/ct_autosign.py +++ b/test/cmdtest_py_d/ct_autosign.py @@ -406,22 +406,23 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase): no_insert_check = False threaded = True - def autosign_start_thread(self): - def run(): - t = self.spawn( - 'mmgen-autosign', - self.opts + ['--full-summary', 'wait'], - direct_exec = True, - no_passthru_opts = True, - spawn_env_override = self.spawn_env | {'EXEC_WRAPPER_DO_RUNTIME_MSG': ''}) - self.write_to_tmpfile('autosign_thread_pid',str(t.ep.pid)) - import threading - threading.Thread(target=run, name='Autosign wait loop').start() - time.sleep(0.2) + def _wait_loop_start(self): + t = self.spawn( + 'mmgen-autosign', + self.opts + ['--full-summary', 'wait'], + direct_exec = True, + no_passthru_opts = True, + spawn_env_override = self.spawn_env | {'EXEC_WRAPPER_DO_RUNTIME_MSG': ''}) + self.write_to_tmpfile('autosign_thread_pid', str(t.ep.pid)) + return t + def wait_loop_start(self): + import threading + threading.Thread(target=self._wait_loop_start, name='Autosign wait loop').start() + time.sleep(0.1) # try to ensure test output is displayed before next test starts return 'silent' - def autosign_kill_thread(self): + def wait_loop_kill(self): self.spawn('',msg_only=True) pid = int(self.read_from_tmpfile('autosign_thread_pid')) self.delete_tmpfile('autosign_thread_pid') diff --git a/test/cmdtest_py_d/ct_xmr_autosign.py b/test/cmdtest_py_d/ct_xmr_autosign.py index 91a66cd0..42f4f5cd 100755 --- a/test/cmdtest_py_d/ct_xmr_autosign.py +++ b/test/cmdtest_py_d/ct_xmr_autosign.py @@ -69,7 +69,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded): ('check_bal_alice1', 'mining, checking balance (wallet #1)'), ('fund_alice2', 'sending funds to Alice (wallet #2)'), ('check_bal_alice2', 'mining, checking balance (wallet #2)'), - ('autosign_start_thread', 'starting autosign wait loop'), + ('wait_loop_start', 'starting autosign wait loop'), ('export_outputs1', 'exporting outputs from Alice’s watch-only wallet #1'), ('create_transfer_tx1', 'creating a transfer TX'), ('submit_transfer_tx1', 'submitting the transfer TX'), @@ -90,7 +90,7 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded): ('export_outputs3', 'exporting outputs from Alice’s watch-only wallets'), ('import_key_images2', 'importing signed key images into Alice’s online wallets'), ('sync_chkbal3', 'syncing Alice’s wallets and checking balance'), - ('autosign_kill_thread', 'stopping autosign wait loop'), + ('wait_loop_kill', 'stopping autosign wait loop'), ('stop_daemons', 'stopping all wallet and coin daemons'), ('view', 'viewing Alice’s wallet in offline mode (wallet #1)'), ('listview', 'list-viewing Alice’s wallet in offline mode (wallet #2)'),