mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
pytest: Use random ports for bitcoind and lightningd to allow parallel testing
Adds a new dependency, but totally worth it :-) Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
bbeb44faac
commit
071ef628db
3 changed files with 14 additions and 9 deletions
|
@ -30,7 +30,7 @@ def test_name(request):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bitcoind(directory):
|
def bitcoind(directory):
|
||||||
bitcoind = utils.BitcoinD(bitcoin_dir=directory, rpcport=28332)
|
bitcoind = utils.BitcoinD(bitcoin_dir=directory, rpcport=None)
|
||||||
try:
|
try:
|
||||||
bitcoind.start()
|
bitcoind.start()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from ephemeral_port_reserve import reserve as reserve_port
|
||||||
from utils import wait_for
|
from utils import wait_for
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
@ -43,7 +44,7 @@ def to_json(arg):
|
||||||
|
|
||||||
def setupBitcoind(directory):
|
def setupBitcoind(directory):
|
||||||
global bitcoind
|
global bitcoind
|
||||||
bitcoind = utils.BitcoinD(bitcoin_dir=directory, rpcport=28332)
|
bitcoind = utils.BitcoinD(bitcoin_dir=directory, rpcport=None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bitcoind.start()
|
bitcoind.start()
|
||||||
|
@ -126,7 +127,8 @@ class NodeFactory(object):
|
||||||
return node_opts, cli_opts
|
return node_opts, cli_opts
|
||||||
|
|
||||||
def get_next_port(self):
|
def get_next_port(self):
|
||||||
return 16330 + self.next_id
|
with self.lock:
|
||||||
|
return reserve_port()
|
||||||
|
|
||||||
def get_nodes(self, num_nodes, opts=None):
|
def get_nodes(self, num_nodes, opts=None):
|
||||||
"""Start a number of nodes in parallel, each with its own options
|
"""Start a number of nodes in parallel, each with its own options
|
||||||
|
@ -148,9 +150,10 @@ class NodeFactory(object):
|
||||||
return [j.result() for j in jobs]
|
return [j.result() for j in jobs]
|
||||||
|
|
||||||
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False, fake_bitcoin_cli=False):
|
def get_node(self, disconnect=None, options=None, may_fail=False, may_reconnect=False, random_hsm=False, fake_bitcoin_cli=False):
|
||||||
node_id = self.next_id
|
with self.lock:
|
||||||
|
node_id = self.next_id
|
||||||
|
self.next_id += 1
|
||||||
port = self.get_next_port()
|
port = self.get_next_port()
|
||||||
self.next_id += 1
|
|
||||||
|
|
||||||
lightning_dir = os.path.join(
|
lightning_dir = os.path.join(
|
||||||
self.directory, "lightning-{}/".format(node_id))
|
self.directory, "lightning-{}/".format(node_id))
|
||||||
|
@ -662,9 +665,7 @@ class LightningDTests(BaseLightningDTests):
|
||||||
"""
|
"""
|
||||||
l1 = self.node_factory.get_node()
|
l1 = self.node_factory.get_node()
|
||||||
l2 = self.node_factory.get_node()
|
l2 = self.node_factory.get_node()
|
||||||
# Force l3 to give its address.
|
l3 = self.node_factory.get_node(options={"ipaddr": "127.0.0.1"})
|
||||||
l3port = self.node_factory.get_next_port()
|
|
||||||
l3 = self.node_factory.get_node(options={"ipaddr": "127.0.0.1:{}".format(l3port)})
|
|
||||||
|
|
||||||
l2.rpc.connect(l3.info['id'], 'localhost', l3.info['port'])
|
l2.rpc.connect(l3.info['id'], 'localhost', l3.info['port'])
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import time
|
||||||
|
|
||||||
from bitcoin.rpc import RawProxy as BitcoinProxy
|
from bitcoin.rpc import RawProxy as BitcoinProxy
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from ephemeral_port_reserve import reserve
|
||||||
|
|
||||||
|
|
||||||
BITCOIND_CONFIG = {
|
BITCOIND_CONFIG = {
|
||||||
|
@ -209,9 +210,12 @@ class SimpleBitcoinProxy:
|
||||||
|
|
||||||
class BitcoinD(TailableProc):
|
class BitcoinD(TailableProc):
|
||||||
|
|
||||||
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=18332):
|
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):
|
||||||
TailableProc.__init__(self, bitcoin_dir, verbose=False)
|
TailableProc.__init__(self, bitcoin_dir, verbose=False)
|
||||||
|
|
||||||
|
if rpcport is None:
|
||||||
|
rpcport = reserve()
|
||||||
|
|
||||||
self.bitcoin_dir = bitcoin_dir
|
self.bitcoin_dir = bitcoin_dir
|
||||||
self.rpcport = rpcport
|
self.rpcport = rpcport
|
||||||
self.prefix = 'bitcoind'
|
self.prefix = 'bitcoind'
|
||||||
|
|
Loading…
Add table
Reference in a new issue