Browse Source

TestProxy: start and stop proxy only when required

The MMGen Project 5 months ago
parent
commit
a8fe14756d

+ 1 - 1
test/cmdtest_d/ethdev.py

@@ -744,7 +744,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 		self.message = 'attack at dawn'
 		self.spawn_env['MMGEN_BOGUS_SEND'] = ''
 
-		TestProxy(cfg)
+		TestProxy(self, cfg)
 
 	@property
 	async def rpc(self):

+ 1 - 1
test/cmdtest_d/ethswap.py

@@ -263,7 +263,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest):
 		self.swap_server = ThornodeSwapServer()
 		self.swap_server.start()
 
-		TestProxy(cfg)
+		TestProxy(self, cfg)
 
 	def swaptxcreate1(self):
 		t = self._swaptxcreate(['BTC', '8.765', 'ETH'])

+ 11 - 6
test/cmdtest_d/include/proxy.py

@@ -55,16 +55,18 @@ class TestProxy:
 
 	def kill_proxy(self, args):
 		if sys.platform in ('linux', 'darwin'):
-			omsg(f'Killing SSH SOCKS server at localhost:{self.port}')
+			omsg(f'Stopping SSH SOCKS server at localhost:{self.port}')
 			cmd = ['pkill', '-f', ' '.join(args)]
 			run(cmd)
 
-	def __init__(self, cfg, external_call=False):
+	def __init__(self, test_group, cfg):
+
+		if test_group and test_group.is_helper:
+			return
 
 		def start_proxy():
-			if external_call or not cfg.no_daemon_autostart:
-				run(a + b2)
-				omsg(f'SSH SOCKS server started, listening at localhost:{self.port}')
+			run(a + b2)
+			omsg(f'SSH SOCKS server started, listening at localhost:{self.port}')
 
 		a = ['ssh', '-x', '-o', 'ExitOnForwardFailure=True', '-D', f'localhost:{self.port}']
 		b0 = ['-o', 'PasswordAuthentication=False']
@@ -89,6 +91,9 @@ class TestProxy:
 			else:
 				die(2, fmt(self.need_start_errmsg.format(' '.join(a + b2)), indent='    '))
 
-		if not (external_call or cfg.no_daemon_stop):
+		if test_group is None:
+			self.kill_proxy(a + b2)
+		elif not hasattr(test_group.tr, 'proxy_stop_registered'):
 			atexit.unregister(self.kill_proxy)
 			atexit.register(self.kill_proxy, a + b2)
+			test_group.tr.proxy_stop_registered = True

+ 1 - 1
test/cmdtest_d/rune.py

@@ -73,7 +73,7 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
 		self.rpc_server = ThornodeRPCServer()
 		self.rpc_server.start()
 
-		TestProxy(cfg)
+		TestProxy(self, cfg)
 
 		self.txhex_file = f'{self.tmpdir}/tx_dump.hex'
 

+ 3 - 3
test/cmdtest_d/runeswap.py

@@ -38,9 +38,9 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest):
 		('subgroup.init',        []),
 		('subgroup.rune_init',   ['init']),
 		('subgroup.rune_swap',   ['rune_init']),
-		('stop',                 'stopping the regtest daemon'),
-		('swap_server_stop',     'stopping the Thornode swap server'),
 		('rune_rpc_server_stop', 'stopping the Thornode RPC server'),
+		('swap_server_stop',     'stopping the Thornode swap server'),
+		('stop',                 'stopping the regtest daemon'),
 	)
 	cmd_subgroups = {
 		'init': (
@@ -81,7 +81,7 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest):
 		self.swap_server = ThornodeSwapServer()
 		self.swap_server.start()
 
-		TestProxy(cfg)
+		TestProxy(self, cfg)
 
 	def swap_server_stop(self):
 		return self._thornode_server_stop()

+ 1 - 1
test/cmdtest_d/xmrwallet.py

@@ -140,7 +140,7 @@ class CmdTestXMRWallet(CmdTestBase):
 			if os.path.exists(self.datadir_base):
 				shutil.rmtree(self.datadir_base)
 			os.makedirs(self.datadir_base)
-			TestProxy(cfg)
+			TestProxy(self, cfg)
 			self.start_daemons()
 
 		self.balance = None

+ 1 - 1
test/modtest_d/testdep.py

@@ -66,4 +66,4 @@ class unit_tests:
 
 	def ssh_socks_proxy(self, name, ut):
 		from test.cmdtest_d.include.proxy import TestProxy
-		return TestProxy(cfg, external_call=True)
+		return TestProxy(None, cfg)