mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
test-db-provider: if postgres in tests, startup a bookkeeper db
FXIME: Has a edge case where if you disable the bookkeeper, it'll blowup because you've got an option that isn't present anywhere...
This commit is contained in:
@@ -17,6 +17,7 @@ from typing import Dict, List, Optional, Union
|
|||||||
class Sqlite3Db(object):
|
class Sqlite3Db(object):
|
||||||
def __init__(self, path: str) -> None:
|
def __init__(self, path: str) -> None:
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.provider = None
|
||||||
|
|
||||||
def get_dsn(self) -> None:
|
def get_dsn(self) -> None:
|
||||||
"""SQLite3 doesn't provide a DSN, resulting in no CLI-option.
|
"""SQLite3 doesn't provide a DSN, resulting in no CLI-option.
|
||||||
@@ -59,6 +60,7 @@ class PostgresDb(object):
|
|||||||
def __init__(self, dbname, port):
|
def __init__(self, dbname, port):
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.provider = None
|
||||||
|
|
||||||
self.conn = psycopg2.connect("dbname={dbname} user=postgres host=localhost port={port}".format(
|
self.conn = psycopg2.connect("dbname={dbname} user=postgres host=localhost port={port}".format(
|
||||||
dbname=dbname, port=port
|
dbname=dbname, port=port
|
||||||
|
|||||||
@@ -1447,6 +1447,7 @@ class NodeFactory(object):
|
|||||||
# Get the DB backend DSN we should be using for this test and this
|
# Get the DB backend DSN we should be using for this test and this
|
||||||
# node.
|
# node.
|
||||||
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
|
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
|
||||||
|
db.provider = self.db_provider
|
||||||
node = self.node_cls(
|
node = self.node_cls(
|
||||||
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
|
node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
|
||||||
port=port, options=options, may_fail=may_fail or expect_fail,
|
port=port, options=options, may_fail=may_fail or expect_fail,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import time
|
|||||||
class Sqlite3Db(object):
|
class Sqlite3Db(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.provider = None
|
||||||
|
|
||||||
def get_dsn(self):
|
def get_dsn(self):
|
||||||
"""SQLite3 doesn't provide a DSN, resulting in no CLI-option.
|
"""SQLite3 doesn't provide a DSN, resulting in no CLI-option.
|
||||||
@@ -54,6 +55,7 @@ class PostgresDb(object):
|
|||||||
def __init__(self, dbname, port):
|
def __init__(self, dbname, port):
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.provider = None
|
||||||
|
|
||||||
self.conn = psycopg2.connect("dbname={dbname} user=postgres host=localhost port={port}".format(
|
self.conn = psycopg2.connect("dbname={dbname} user=postgres host=localhost port={port}".format(
|
||||||
dbname=dbname, port=port
|
dbname=dbname, port=port
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class LightningNode(utils.LightningNode):
|
|||||||
# If we opted into checking the DB statements we will attach the dblog
|
# If we opted into checking the DB statements we will attach the dblog
|
||||||
# plugin before starting the node
|
# plugin before starting the node
|
||||||
check_dblog = os.environ.get("TEST_CHECK_DBSTMTS", None) == "1"
|
check_dblog = os.environ.get("TEST_CHECK_DBSTMTS", None) == "1"
|
||||||
db = os.environ.get("TEST_DB_PROVIDER", "sqlite3")
|
db_type = os.environ.get("TEST_DB_PROVIDER", "sqlite3")
|
||||||
if db == 'sqlite3' and check_dblog:
|
if db_type == 'sqlite3' and check_dblog:
|
||||||
dblog = os.path.join(os.path.dirname(__file__), 'plugins', 'dblog.py')
|
dblog = os.path.join(os.path.dirname(__file__), 'plugins', 'dblog.py')
|
||||||
has_dblog = len([o for o in self.daemon.cmd_line if 'dblog.py' in o]) > 0
|
has_dblog = len([o for o in self.daemon.cmd_line if 'dblog.py' in o]) > 0
|
||||||
if not has_dblog:
|
if not has_dblog:
|
||||||
@@ -42,6 +42,11 @@ class LightningNode(utils.LightningNode):
|
|||||||
self.daemon.opts['plugin={}'.format(dblog)] = None
|
self.daemon.opts['plugin={}'.format(dblog)] = None
|
||||||
self.daemon.opts['dblog-file'] = 'dblog.sqlite3'
|
self.daemon.opts['dblog-file'] = 'dblog.sqlite3'
|
||||||
|
|
||||||
|
# FIXME: make sure bookkeeper is not disabled
|
||||||
|
if db_type == 'postgres':
|
||||||
|
accts_db = self.db.provider.get_db('', 'accounts', 0)
|
||||||
|
self.daemon.opts['bookkeeper-db'] = accts_db.get_dsn()
|
||||||
|
|
||||||
# Yes, we really want to test the local development version, not
|
# Yes, we really want to test the local development version, not
|
||||||
# something in out path.
|
# something in out path.
|
||||||
self.daemon.executable = 'lightningd/lightningd'
|
self.daemon.executable = 'lightningd/lightningd'
|
||||||
|
|||||||
@@ -2126,6 +2126,7 @@ def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db
|
|||||||
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
|
lightning_dir = os.path.join(directory, "anode" + "far" * 30 + "away")
|
||||||
os.makedirs(lightning_dir)
|
os.makedirs(lightning_dir)
|
||||||
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
|
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
|
||||||
|
db.provider = db_provider
|
||||||
|
|
||||||
l1 = LightningNode(1, lightning_dir, bitcoind, executor, VALGRIND, db=db, port=reserve())
|
l1 = LightningNode(1, lightning_dir, bitcoind, executor, VALGRIND, db=db, port=reserve())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user