itest: add the -nativesql flag to run SQL itests with native SQL tables

This commit is contained in:
Andras Banki-Horvath 2023-12-12 14:50:15 +01:00
parent 7a45bbbeab
commit ba8e7550d5
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
6 changed files with 29 additions and 7 deletions

View file

@ -71,6 +71,9 @@ var (
dbBackendFlag = flag.String("dbbackend", "bbolt", "Database backend "+
"(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 = flag.String(
"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.
binary := getLndBinary(t)
harnessTest := lntest.SetupHarness(
t, binary, *dbBackendFlag, feeService,
t, binary, *dbBackendFlag, *nativeSQLFlag, feeService,
)
defer harnessTest.Stop()

View file

@ -103,14 +103,14 @@ type HarnessTest struct {
// NewHarnessTest creates a new instance of a harnessTest from a regular
// testing.T instance.
func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
dbBackend node.DatabaseBackend) *HarnessTest {
dbBackend node.DatabaseBackend, nativeSQL bool) *HarnessTest {
t.Helper()
// Create the run context.
ctxt, cancel := context.WithCancel(context.Background())
manager := newNodeManager(lndBinary, dbBackend)
manager := newNodeManager(lndBinary, dbBackend, nativeSQL)
return &HarnessTest{
T: t,

View file

@ -31,6 +31,10 @@ type nodeManager struct {
// dbBackend sets the database backend to use.
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:
// {pubkey: *HarnessNode}.
activeNodes map[uint32]*node.HarnessNode
@ -48,12 +52,13 @@ type nodeManager struct {
}
// newNodeManager creates a new node manager instance.
func newNodeManager(lndBinary string,
dbBackend node.DatabaseBackend) *nodeManager {
func newNodeManager(lndBinary string, dbBackend node.DatabaseBackend,
nativeSQL bool) *nodeManager {
return &nodeManager{
lndBinary: lndBinary,
dbBackend: dbBackend,
nativeSQL: nativeSQL,
activeNodes: 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,
FeeURL: nm.feeServiceURL,
DBBackend: nm.dbBackend,
NativeSQL: nm.nativeSQL,
NodeID: nm.nextNodeID(),
LndBinary: nm.lndBinary,
NetParams: harnessNetParams,

View file

@ -18,7 +18,7 @@ import (
// 4. connect the miner and the chain backend.
// 5. start the HarnessTest.
func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
feeService WebFeeService) *HarnessTest {
nativeSQL bool, feeService WebFeeService) *HarnessTest {
t.Log("Setting up HarnessTest...")
@ -30,7 +30,7 @@ func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
dbBackend := prepareDBBackend(t, dbBackendName)
// Create a new HarnessTest.
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend)
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend, nativeSQL)
// Init the miner.
t.Log("Prepare the miner and mine blocks to activate segwit...")

View file

@ -119,6 +119,7 @@ type BaseNodeConfig struct {
DBBackend DatabaseBackend
PostgresDsn string
NativeSQL bool
// NodeID is a unique ID used to identify the node.
NodeID uint32
@ -277,11 +278,17 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
case BackendPostgres:
args = append(args, "--db.backend=postgres")
args = append(args, "--db.postgres.dsn="+cfg.PostgresDsn)
if cfg.NativeSQL {
args = append(args, "--db.use-native-sql")
}
case BackendSqlite:
args = append(args, "--db.backend=sqlite")
args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v",
wait.SqliteBusyTimeout))
if cfg.NativeSQL {
args = append(args, "--db.use-native-sql")
}
}
if cfg.FeeURL != "" {

View file

@ -60,10 +60,16 @@ DEV_TAGS += kvdb_etcd
endif
ifeq ($(dbbackend),postgres)
ifneq ($(nativesql),)
ITEST_FLAGS += -nativesql
endif
DEV_TAGS += kvdb_postgres
endif
ifeq ($(dbbackend),sqlite)
ifneq ($(nativesql),)
ITEST_FLAGS += -nativesql
endif
DEV_TAGS += kvdb_sqlite
endif