From 3f5ce98fdaf8a5d556333dc1d80febd31daf8576 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 30 Dec 2024 11:31:40 +0000 Subject: [PATCH] test suite: remove datadir after stopping daemons --- test/cmdtest_d/ct_autosign.py | 2 +- test/cmdtest_d/ct_ethdev.py | 2 +- test/cmdtest_d/ct_misc.py | 2 +- test/cmdtest_d/ct_ref_altcoin.py | 2 +- test/daemontest_d/ut_exec.py | 2 +- test/daemontest_d/ut_msg.py | 2 +- test/include/coin_daemon_control.py | 6 +++++- test/include/common.py | 2 +- 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/cmdtest_d/ct_autosign.py b/test/cmdtest_d/ct_autosign.py index 71631ac1..e06cea64 100755 --- a/test/cmdtest_d/ct_autosign.py +++ b/test/cmdtest_d/ct_autosign.py @@ -186,7 +186,7 @@ class CmdTestAutosignBase(CmdTestBase): def stop_daemons(self): self.spawn('', msg_only=True) - stop_test_daemons(*self.network_ids) + stop_test_daemons(*self.network_ids, remove_datadir=True) return 'ok' def run_setup( diff --git a/test/cmdtest_d/ct_ethdev.py b/test/cmdtest_d/ct_ethdev.py index 00aa4fa4..7fec53fb 100755 --- a/test/cmdtest_d/ct_ethdev.py +++ b/test/cmdtest_d/ct_ethdev.py @@ -1493,7 +1493,7 @@ class CmdTestEthdev(CmdTestBase, CmdTestShared): def stop(self): self.spawn('', msg_only=True) if not cfg.no_daemon_stop: - if not stop_test_daemons(self.proto.coin+'_rt'): + if not stop_test_daemons(self.proto.coin+'_rt', remove_datadir=True): return False set_vt100() return 'ok' diff --git a/test/cmdtest_d/ct_misc.py b/test/cmdtest_d/ct_misc.py index 507d81bb..a1707eb9 100755 --- a/test/cmdtest_d/ct_misc.py +++ b/test/cmdtest_d/ct_misc.py @@ -141,7 +141,7 @@ class CmdTestMisc(CmdTestBase): if cfg.pexpect_spawn: t.send('q') if not cfg.no_altcoin: - stop_test_daemons('ltc', 'eth') + stop_test_daemons('ltc', 'eth', remove_datadir=True) return t def term_echo(self): diff --git a/test/cmdtest_d/ct_ref_altcoin.py b/test/cmdtest_d/ct_ref_altcoin.py index c3c96dc7..732751bd 100755 --- a/test/cmdtest_d/ct_ref_altcoin.py +++ b/test/cmdtest_d/ct_ref_altcoin.py @@ -113,7 +113,7 @@ class CmdTestRefAltcoin(CmdTestRef, CmdTestBase): t.read() t.ok() if proto.sign_mode == 'daemon' and not proto.network_id == 'btc': - stop_test_daemons(proto.network_id) + stop_test_daemons(proto.network_id, remove_datadir=True) return 'ok' def ref_altcoin_addrgen( diff --git a/test/daemontest_d/ut_exec.py b/test/daemontest_d/ut_exec.py index 68c59eb9..a0c8674d 100755 --- a/test/daemontest_d/ut_exec.py +++ b/test/daemontest_d/ut_exec.py @@ -113,4 +113,4 @@ class unit_tests: return self._test_cmd(['start'], 'Checking status of coin daemons...') def stop(self, name, ut): - return self._test_cmd(['stop'], 'Stopping coin daemons...') + return self._test_cmd(['stop', '--remove-datadir'], 'Stopping coin daemons...') diff --git a/test/daemontest_d/ut_msg.py b/test/daemontest_d/ut_msg.py index cf91dec4..811edf85 100755 --- a/test/daemontest_d/ut_msg.py +++ b/test/daemontest_d/ut_msg.py @@ -116,7 +116,7 @@ async def run_test(network_id, chksum, msghash_type='raw'): msg(m.format(single_addr_coin)) if m.proto.sign_mode == 'daemon': - stop_test_daemons(network_id) + stop_test_daemons(network_id, remove_datadir=True) msg('\n') diff --git a/test/include/coin_daemon_control.py b/test/include/coin_daemon_control.py index 33fbd504..0be51850 100755 --- a/test/include/coin_daemon_control.py +++ b/test/include/coin_daemon_control.py @@ -43,6 +43,7 @@ opts_data = { -m, --mainnet-only Perform operations for mainnet daemons only -n, --no-daemonize Don't fork daemon to background -p, --port-shift= Shift the RPC port by this number +-r, --remove-datadir Remove the datadir(s) after stopping the daemon(s) -s, --get-state Get the state of the daemon(s) and exit -t, --testing Testing mode. Print commands but don't execute them -q, --quiet Produce quieter output @@ -99,7 +100,7 @@ def run(network_id=None, proto=None, daemon_id=None, missing_exec_ok=False): return d.debug = d.debug or cfg.debug - d.wait = not cfg.no_wait + d.wait = cfg.remove_datadir or not cfg.no_wait if missing_exec_ok: try: @@ -121,6 +122,9 @@ def run(network_id=None, proto=None, daemon_id=None, missing_exec_ok=False): async_run(d.rpc.stop_daemon(quiet=cfg.quiet)) else: d.cmd(action, quiet=cfg.quiet) + if action == 'stop' and cfg.remove_datadir: + cfg._util.vmsg(f'Removing ‘{d.datadir}’') + d.remove_datadir() def main(): diff --git a/test/include/common.py b/test/include/common.py index db0ae247..878fb362 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -296,7 +296,7 @@ def stop_test_daemons(*network_ids, force=False, remove_datadir=False): return test_daemons_ops(*network_ids, op='stop', remove_datadir=remove_datadir) def restart_test_daemons(*network_ids, remove_datadir=False): - if not stop_test_daemons(*network_ids): + if not stop_test_daemons(*network_ids, remove_datadir=remove_datadir): return False return start_test_daemons(*network_ids, remove_datadir=remove_datadir)