test: Wait for rpc.

2024-05-20_merge
tecnovert 6 years ago
parent e242f50b2b
commit 6c0d82abe6
No known key found for this signature in database
GPG Key ID: 13F13651C9CF0D6B
  1. 11
      basicswap/basicswap.py
  2. 13
      tests/test_run.py

@ -573,17 +573,14 @@ class BasicSwap():
for i in range(21): for i in range(21):
if not self.is_running: if not self.is_running:
return return
if i == 20:
self.log.error('Can\'t connect to daemon RPC, exiting.')
self.stopRunning(1) # systemd will try restart if fail_code != 0
return
try: try:
self.callrpc('getwalletinfo', [], self.wallet) self.callrpc('getwalletinfo', [], self.wallet)
break return
except Exception as ex: except Exception as ex:
traceback.print_exc() logging.warning('Can\'t connect to daemon RPC: %s. Trying again in %d second/s.', str(ex), (1 + i))
self.log.warning('Can\'t connect to daemon RPC, trying again in %d second/s.', (1 + i))
time.sleep(1 + i) time.sleep(1 + i)
self.log.error('Can\'t connect to daemon RPC, exiting.')
self.stopRunning(1) # systemd will try restart if fail_code != 0
def loadFromDB(self): def loadFromDB(self):
self.log.info('Loading data from db') self.log.info('Loading data from db')

@ -207,6 +207,17 @@ def run_loop(self):
btcRpc('generatetoaddress 1 {}'.format(self.btc_addr)) btcRpc('generatetoaddress 1 {}'.format(self.btc_addr))
def waitForRPC(rpc_func, wallet=None):
for i in range(5):
try:
rpc_func('getwalletinfo')
return
except Exception as ex:
logging.warning('Can\'t connect to daemon RPC: %s. Trying again in %d second/s.', str(ex), (1 + i))
time.sleep(1 + i)
raise ValueError('waitForRPC failed')
class Test(unittest.TestCase): class Test(unittest.TestCase):
@classmethod @classmethod
@ -253,6 +264,7 @@ class Test(unittest.TestCase):
cls.swap_clients[1].callrpc('getnewextaddress', ['lblExtTest']) cls.swap_clients[1].callrpc('getnewextaddress', ['lblExtTest'])
cls.swap_clients[1].callrpc('rescanblockchain') cls.swap_clients[1].callrpc('rescanblockchain')
waitForRPC(ltcRpc)
num_blocks = 500 num_blocks = 500
logging.info('Mining %d litecoin blocks', num_blocks) logging.info('Mining %d litecoin blocks', num_blocks)
cls.ltc_addr = ltcRpc('getnewaddress mining_addr legacy') cls.ltc_addr = ltcRpc('getnewaddress mining_addr legacy')
@ -262,6 +274,7 @@ class Test(unittest.TestCase):
assert(ro['bip9_softforks']['csv']['status'] == 'active') assert(ro['bip9_softforks']['csv']['status'] == 'active')
assert(ro['bip9_softforks']['segwit']['status'] == 'active') assert(ro['bip9_softforks']['segwit']['status'] == 'active')
waitForRPC(btcRpc)
cls.btc_addr = btcRpc('getnewaddress mining_addr bech32') cls.btc_addr = btcRpc('getnewaddress mining_addr bech32')
logging.info('Mining %d bitcoin blocks to %s', num_blocks, cls.btc_addr) logging.info('Mining %d bitcoin blocks to %s', num_blocks, cls.btc_addr)
btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr)) btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr))

Loading…
Cancel
Save