mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-23 03:49:25 +00:00
test: Wait for rpc.
This commit is contained in:
parent
e242f50b2b
commit
6c0d82abe6
2 changed files with 17 additions and 7 deletions
|
@ -573,17 +573,14 @@ class BasicSwap():
|
|||
for i in range(21):
|
||||
if not self.is_running:
|
||||
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:
|
||||
self.callrpc('getwalletinfo', [], self.wallet)
|
||||
break
|
||||
return
|
||||
except Exception as ex:
|
||||
traceback.print_exc()
|
||||
self.log.warning('Can\'t connect to daemon RPC, trying again in %d second/s.', (1 + i))
|
||||
logging.warning('Can\'t connect to daemon RPC: %s. Trying again in %d second/s.', str(ex), (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):
|
||||
self.log.info('Loading data from db')
|
||||
|
|
|
@ -207,6 +207,17 @@ def run_loop(self):
|
|||
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):
|
||||
|
||||
@classmethod
|
||||
|
@ -253,6 +264,7 @@ class Test(unittest.TestCase):
|
|||
cls.swap_clients[1].callrpc('getnewextaddress', ['lblExtTest'])
|
||||
cls.swap_clients[1].callrpc('rescanblockchain')
|
||||
|
||||
waitForRPC(ltcRpc)
|
||||
num_blocks = 500
|
||||
logging.info('Mining %d litecoin blocks', num_blocks)
|
||||
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']['segwit']['status'] == 'active')
|
||||
|
||||
waitForRPC(btcRpc)
|
||||
cls.btc_addr = btcRpc('getnewaddress mining_addr bech32')
|
||||
logging.info('Mining %d bitcoin blocks to %s', num_blocks, cls.btc_addr)
|
||||
btcRpc('generatetoaddress {} {}'.format(num_blocks, cls.btc_addr))
|
||||
|
|
Loading…
Reference in a new issue