functional_tests: support several daemons/wallets

This commit is contained in:
moneromooo-monero 2019-03-18 11:53:47 +00:00
parent 9e979ffa22
commit b2fc571943
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 42 additions and 29 deletions

View file

@ -33,35 +33,46 @@ try:
except: except:
tests = DEFAULT_TESTS tests = DEFAULT_TESTS
monerod = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", "1", "--offline", "--no-igd", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--log-level", "1"] N_MONERODS = 1
wallet = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", builddir + "/functional-tests-directory", "--rpc-bind-port", "18083", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1"] N_WALLETS = 3
monerod_output = open(builddir + '/tests/functional_tests/monerod.log', 'a+') monerod_base = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", "1", "--offline", "--no-igd", "--p2p-bind-port", "monerod_p2p_port", "--rpc-bind-port", "monerod_rpc_port", "--zmq-rpc-bind-port", "monerod_zmq_port", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--log-level", "1"]
wallet_output = open(builddir + '/tests/functional_tests/wallet.log', 'a+') wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", builddir + "/functional-tests-directory", "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--daemon-port", "18180", "--log-level", "1"]
command_lines = []
processes = []
outputs = []
ports = []
for i in range(N_MONERODS):
command_lines.append([str(18180+i) if x == "monerod_rpc_port" else str(18280+i) if x == "monerod_p2p_port" else str(18380+i) if x == "monerod_zmq_port" else x for x in monerod_base])
outputs.append(open(builddir + '/tests/functional_tests/monerod' + str(i) + '.log', 'a+'))
ports.append(18180+i)
for i in range(N_WALLETS):
command_lines.append([str(18090+i) if x == "wallet_port" else x for x in wallet_base])
outputs.append(open(builddir + '/tests/functional_tests/wallet' + str(i) + '.log', 'a+'))
ports.append(18090+i)
print('Starting servers...') print('Starting servers...')
monerod_process = None
wallet_process = None
try: try:
#print 'Running: ' + str(monerod) for i in range(len(command_lines)):
monerod_process = subprocess.Popen(monerod, stdout = monerod_output) #print('Running: ' + str(command_lines[i]))
#print 'Running: ' + str(wallet) processes.append(subprocess.Popen(command_lines[i], stdout = outputs[i]))
wallet_process = subprocess.Popen(wallet, stdout = wallet_output)
except Exception, e: except Exception, e:
print('Error: ' + str(e)) print('Error: ' + str(e))
sys.exit(1) sys.exit(1)
def kill(): def kill():
try: wallet_process.send_signal(SIGTERM) for i in range(len(processes)):
except: pass try: processes[i].send_signal(SIGTERM)
try: monerod_process.send_signal(SIGTERM) except: pass
except: pass
# wait for error/startup # wait for error/startup
for i in range(10): for i in range(10):
time.sleep(1) time.sleep(1)
all_open = True all_open = True
for port in [18081, 18083]: for port in ports:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1) s.settimeout(1)
if s.connect_ex(('127.0.0.1', port)) != 0: if s.connect_ex(('127.0.0.1', port)) != 0:
@ -95,20 +106,22 @@ kill()
# wait for exit, the poll method does not work (https://bugs.python.org/issue2475) so we wait, possibly forever if the process hangs # wait for exit, the poll method does not work (https://bugs.python.org/issue2475) so we wait, possibly forever if the process hangs
if True: if True:
wallet_process.wait() for p in processes:
monerod_process.wait() p.wait()
else: else:
for i in range(10): for i in range(10):
wallet_process.poll() n_returncode = 0
monerod_process.poll() for p in processes:
if wallet_process.returncode and monerod_process.returncode: p.poll()
print('Both done: ' + str(wallet_process.returncode) + ' and ' + str(monerod_process.returncode)) if p.returncode:
n_returncode += 1
if n_returncode == len(processes):
print('All done: ' + string.join([x.returncode for x in processes], ', '))
break break
time.sleep(1) time.sleep(1)
if not wallet_process.returncode: for p in processes:
print('Failed to stop monero-wallet-rpc') if not p.returncode:
if not monerod_process.returncode: print('Failed to stop process')
print('Failed to stop monerod')
if len(FAIL) == 0: if len(FAIL) == 0:
print('Done, ' + str(len(PASS)) + '/' + str(len(tests)) + ' tests passed') print('Done, ' + str(len(PASS)) + '/' + str(len(tests)) + ' tests passed')

View file

@ -32,8 +32,8 @@ from .rpc import JSONRPC
class Daemon(object): class Daemon(object):
def __init__(self, protocol='http', host='127.0.0.1', port=18081): def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0):
self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port)) self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18180+idx))
def getblocktemplate(self, address): def getblocktemplate(self, address):
getblocktemplate = { getblocktemplate = {

View file

@ -32,8 +32,8 @@ from .rpc import JSONRPC
class Wallet(object): class Wallet(object):
def __init__(self, protocol='http', host='127.0.0.1', port=18083): def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0):
self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port)) self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18090+idx))
def make_uniform_destinations(self, address, transfer_amount, transfer_number_of_destinations=1): def make_uniform_destinations(self, address, transfer_amount, transfer_number_of_destinations=1):
destinations = [] destinations = []