mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
pytest: Have bitcoind own its proxies
We were restarting the with the nodes before, which was causing some port contention. This is more natural since `bitcoind` will take care of terminating all proxies it returned. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
f687262658
commit
5a55972f1a
@ -93,7 +93,7 @@ def bitcoind(directory):
|
|||||||
yield bitcoind
|
yield bitcoind
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bitcoind.rpc.stop()
|
bitcoind.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
bitcoind.proc.kill()
|
bitcoind.proc.kill()
|
||||||
bitcoind.proc.wait()
|
bitcoind.proc.wait()
|
||||||
|
@ -298,6 +298,7 @@ class BitcoinD(TailableProc):
|
|||||||
btc_conf_file = os.path.join(bitcoin_dir, 'bitcoin.conf')
|
btc_conf_file = os.path.join(bitcoin_dir, 'bitcoin.conf')
|
||||||
write_config(btc_conf_file, BITCOIND_CONFIG, BITCOIND_REGTEST)
|
write_config(btc_conf_file, BITCOIND_CONFIG, BITCOIND_REGTEST)
|
||||||
self.rpc = SimpleBitcoinProxy(btc_conf_file=btc_conf_file)
|
self.rpc = SimpleBitcoinProxy(btc_conf_file=btc_conf_file)
|
||||||
|
self.proxies = []
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
TailableProc.start(self)
|
TailableProc.start(self)
|
||||||
@ -305,13 +306,24 @@ class BitcoinD(TailableProc):
|
|||||||
|
|
||||||
logging.info("BitcoinD started")
|
logging.info("BitcoinD started")
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
for p in self.proxies:
|
||||||
|
p.stop()
|
||||||
|
self.rpc.stop()
|
||||||
|
return TailableProc.stop(self)
|
||||||
|
|
||||||
|
def get_proxy(self):
|
||||||
|
proxy = BitcoinRpcProxy(self)
|
||||||
|
self.proxies.append(proxy)
|
||||||
|
return proxy
|
||||||
|
|
||||||
def generate_block(self, numblocks=1):
|
def generate_block(self, numblocks=1):
|
||||||
# As of 0.16, generate() is removed; use generatetoaddress.
|
# As of 0.16, generate() is removed; use generatetoaddress.
|
||||||
return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())
|
return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())
|
||||||
|
|
||||||
|
|
||||||
class LightningD(TailableProc):
|
class LightningD(TailableProc):
|
||||||
def __init__(self, lightning_dir, bitcoind, port=9735, random_hsm=False, node_id=0):
|
def __init__(self, lightning_dir, bitcoindproxy, port=9735, random_hsm=False, node_id=0):
|
||||||
TailableProc.__init__(self, lightning_dir)
|
TailableProc.__init__(self, lightning_dir)
|
||||||
self.executable = 'lightningd/lightningd'
|
self.executable = 'lightningd/lightningd'
|
||||||
self.lightning_dir = lightning_dir
|
self.lightning_dir = lightning_dir
|
||||||
@ -319,7 +331,7 @@ class LightningD(TailableProc):
|
|||||||
self.cmd_prefix = []
|
self.cmd_prefix = []
|
||||||
self.disconnect_file = None
|
self.disconnect_file = None
|
||||||
|
|
||||||
self.rpcproxy = BitcoinRpcProxy(bitcoind)
|
self.rpcproxy = bitcoindproxy
|
||||||
|
|
||||||
self.opts = LIGHTNINGD_CONFIG.copy()
|
self.opts = LIGHTNINGD_CONFIG.copy()
|
||||||
opts = {
|
opts = {
|
||||||
@ -384,7 +396,6 @@ class LightningD(TailableProc):
|
|||||||
not return before the timeout triggers.
|
not return before the timeout triggers.
|
||||||
"""
|
"""
|
||||||
self.proc.wait(timeout)
|
self.proc.wait(timeout)
|
||||||
self.rpcproxy.stop()
|
|
||||||
return self.proc.returncode
|
return self.proc.returncode
|
||||||
|
|
||||||
|
|
||||||
@ -743,7 +754,7 @@ class NodeFactory(object):
|
|||||||
|
|
||||||
socket_path = os.path.join(lightning_dir, "lightning-rpc").format(node_id)
|
socket_path = os.path.join(lightning_dir, "lightning-rpc").format(node_id)
|
||||||
daemon = LightningD(
|
daemon = LightningD(
|
||||||
lightning_dir, self.bitcoind,
|
lightning_dir, bitcoindproxy=self.bitcoind.get_proxy(),
|
||||||
port=port, random_hsm=random_hsm, node_id=node_id
|
port=port, random_hsm=random_hsm, node_id=node_id
|
||||||
)
|
)
|
||||||
# If we have a disconnect string, dump it to a file for daemon.
|
# If we have a disconnect string, dump it to a file for daemon.
|
||||||
|
Loading…
Reference in New Issue
Block a user