mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-23 15:22:38 +02:00
itest: add the -nativesql flag to run SQL itests with native SQL tables
This commit is contained in:
parent
7a45bbbeab
commit
ba8e7550d5
@ -71,6 +71,9 @@ var (
|
|||||||
dbBackendFlag = flag.String("dbbackend", "bbolt", "Database backend "+
|
dbBackendFlag = flag.String("dbbackend", "bbolt", "Database backend "+
|
||||||
"(bbolt, etcd, postgres)")
|
"(bbolt, etcd, postgres)")
|
||||||
|
|
||||||
|
nativeSQLFlag = flag.Bool("nativesql", false, "Database backend to "+
|
||||||
|
"use native SQL when applicable (only for sqlite and postgres")
|
||||||
|
|
||||||
// lndExecutable is the full path to the lnd binary.
|
// lndExecutable is the full path to the lnd binary.
|
||||||
lndExecutable = flag.String(
|
lndExecutable = flag.String(
|
||||||
"lndexec", itestLndBinary, "full path to lnd binary",
|
"lndexec", itestLndBinary, "full path to lnd binary",
|
||||||
@ -95,7 +98,7 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
|||||||
// Get the binary path and setup the harness test.
|
// Get the binary path and setup the harness test.
|
||||||
binary := getLndBinary(t)
|
binary := getLndBinary(t)
|
||||||
harnessTest := lntest.SetupHarness(
|
harnessTest := lntest.SetupHarness(
|
||||||
t, binary, *dbBackendFlag, feeService,
|
t, binary, *dbBackendFlag, *nativeSQLFlag, feeService,
|
||||||
)
|
)
|
||||||
defer harnessTest.Stop()
|
defer harnessTest.Stop()
|
||||||
|
|
||||||
|
@ -103,14 +103,14 @@ type HarnessTest struct {
|
|||||||
// NewHarnessTest creates a new instance of a harnessTest from a regular
|
// NewHarnessTest creates a new instance of a harnessTest from a regular
|
||||||
// testing.T instance.
|
// testing.T instance.
|
||||||
func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
|
func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
|
||||||
dbBackend node.DatabaseBackend) *HarnessTest {
|
dbBackend node.DatabaseBackend, nativeSQL bool) *HarnessTest {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
// Create the run context.
|
// Create the run context.
|
||||||
ctxt, cancel := context.WithCancel(context.Background())
|
ctxt, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
manager := newNodeManager(lndBinary, dbBackend)
|
manager := newNodeManager(lndBinary, dbBackend, nativeSQL)
|
||||||
|
|
||||||
return &HarnessTest{
|
return &HarnessTest{
|
||||||
T: t,
|
T: t,
|
||||||
|
@ -31,6 +31,10 @@ type nodeManager struct {
|
|||||||
// dbBackend sets the database backend to use.
|
// dbBackend sets the database backend to use.
|
||||||
dbBackend node.DatabaseBackend
|
dbBackend node.DatabaseBackend
|
||||||
|
|
||||||
|
// nativeSQL sets the database backend to use native SQL when
|
||||||
|
// applicable.
|
||||||
|
nativeSQL bool
|
||||||
|
|
||||||
// activeNodes is a map of all running nodes, format:
|
// activeNodes is a map of all running nodes, format:
|
||||||
// {pubkey: *HarnessNode}.
|
// {pubkey: *HarnessNode}.
|
||||||
activeNodes map[uint32]*node.HarnessNode
|
activeNodes map[uint32]*node.HarnessNode
|
||||||
@ -48,12 +52,13 @@ type nodeManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newNodeManager creates a new node manager instance.
|
// newNodeManager creates a new node manager instance.
|
||||||
func newNodeManager(lndBinary string,
|
func newNodeManager(lndBinary string, dbBackend node.DatabaseBackend,
|
||||||
dbBackend node.DatabaseBackend) *nodeManager {
|
nativeSQL bool) *nodeManager {
|
||||||
|
|
||||||
return &nodeManager{
|
return &nodeManager{
|
||||||
lndBinary: lndBinary,
|
lndBinary: lndBinary,
|
||||||
dbBackend: dbBackend,
|
dbBackend: dbBackend,
|
||||||
|
nativeSQL: nativeSQL,
|
||||||
activeNodes: make(map[uint32]*node.HarnessNode),
|
activeNodes: make(map[uint32]*node.HarnessNode),
|
||||||
standbyNodes: make(map[uint32]*node.HarnessNode),
|
standbyNodes: make(map[uint32]*node.HarnessNode),
|
||||||
}
|
}
|
||||||
@ -80,6 +85,7 @@ func (nm *nodeManager) newNode(t *testing.T, name string, extraArgs []string,
|
|||||||
ExtraArgs: extraArgs,
|
ExtraArgs: extraArgs,
|
||||||
FeeURL: nm.feeServiceURL,
|
FeeURL: nm.feeServiceURL,
|
||||||
DBBackend: nm.dbBackend,
|
DBBackend: nm.dbBackend,
|
||||||
|
NativeSQL: nm.nativeSQL,
|
||||||
NodeID: nm.nextNodeID(),
|
NodeID: nm.nextNodeID(),
|
||||||
LndBinary: nm.lndBinary,
|
LndBinary: nm.lndBinary,
|
||||||
NetParams: harnessNetParams,
|
NetParams: harnessNetParams,
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
// 4. connect the miner and the chain backend.
|
// 4. connect the miner and the chain backend.
|
||||||
// 5. start the HarnessTest.
|
// 5. start the HarnessTest.
|
||||||
func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
|
func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
|
||||||
feeService WebFeeService) *HarnessTest {
|
nativeSQL bool, feeService WebFeeService) *HarnessTest {
|
||||||
|
|
||||||
t.Log("Setting up HarnessTest...")
|
t.Log("Setting up HarnessTest...")
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
|
|||||||
dbBackend := prepareDBBackend(t, dbBackendName)
|
dbBackend := prepareDBBackend(t, dbBackendName)
|
||||||
|
|
||||||
// Create a new HarnessTest.
|
// Create a new HarnessTest.
|
||||||
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend)
|
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend, nativeSQL)
|
||||||
|
|
||||||
// Init the miner.
|
// Init the miner.
|
||||||
t.Log("Prepare the miner and mine blocks to activate segwit...")
|
t.Log("Prepare the miner and mine blocks to activate segwit...")
|
||||||
|
@ -119,6 +119,7 @@ type BaseNodeConfig struct {
|
|||||||
|
|
||||||
DBBackend DatabaseBackend
|
DBBackend DatabaseBackend
|
||||||
PostgresDsn string
|
PostgresDsn string
|
||||||
|
NativeSQL bool
|
||||||
|
|
||||||
// NodeID is a unique ID used to identify the node.
|
// NodeID is a unique ID used to identify the node.
|
||||||
NodeID uint32
|
NodeID uint32
|
||||||
@ -277,11 +278,17 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
|
|||||||
case BackendPostgres:
|
case BackendPostgres:
|
||||||
args = append(args, "--db.backend=postgres")
|
args = append(args, "--db.backend=postgres")
|
||||||
args = append(args, "--db.postgres.dsn="+cfg.PostgresDsn)
|
args = append(args, "--db.postgres.dsn="+cfg.PostgresDsn)
|
||||||
|
if cfg.NativeSQL {
|
||||||
|
args = append(args, "--db.use-native-sql")
|
||||||
|
}
|
||||||
|
|
||||||
case BackendSqlite:
|
case BackendSqlite:
|
||||||
args = append(args, "--db.backend=sqlite")
|
args = append(args, "--db.backend=sqlite")
|
||||||
args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v",
|
args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v",
|
||||||
wait.SqliteBusyTimeout))
|
wait.SqliteBusyTimeout))
|
||||||
|
if cfg.NativeSQL {
|
||||||
|
args = append(args, "--db.use-native-sql")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.FeeURL != "" {
|
if cfg.FeeURL != "" {
|
||||||
|
@ -60,10 +60,16 @@ DEV_TAGS += kvdb_etcd
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(dbbackend),postgres)
|
ifeq ($(dbbackend),postgres)
|
||||||
|
ifneq ($(nativesql),)
|
||||||
|
ITEST_FLAGS += -nativesql
|
||||||
|
endif
|
||||||
DEV_TAGS += kvdb_postgres
|
DEV_TAGS += kvdb_postgres
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(dbbackend),sqlite)
|
ifeq ($(dbbackend),sqlite)
|
||||||
|
ifneq ($(nativesql),)
|
||||||
|
ITEST_FLAGS += -nativesql
|
||||||
|
endif
|
||||||
DEV_TAGS += kvdb_sqlite
|
DEV_TAGS += kvdb_sqlite
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user