From ba8e7550d5f2fa522ddbb7d135aabf7e2f26c530 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Tue, 12 Dec 2023 14:50:15 +0100 Subject: [PATCH] itest: add the -nativesql flag to run SQL itests with native SQL tables --- itest/lnd_test.go | 5 ++++- lntest/harness.go | 4 ++-- lntest/harness_node_manager.go | 10 ++++++++-- lntest/harness_setup.go | 4 ++-- lntest/node/config.go | 7 +++++++ make/testing_flags.mk | 6 ++++++ 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/itest/lnd_test.go b/itest/lnd_test.go index cb9f60dbf..9c823b5a8 100644 --- a/itest/lnd_test.go +++ b/itest/lnd_test.go @@ -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() diff --git a/lntest/harness.go b/lntest/harness.go index 23f5a8b43..c4996a730 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -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, diff --git a/lntest/harness_node_manager.go b/lntest/harness_node_manager.go index dd1b59ea3..3b0c412d9 100644 --- a/lntest/harness_node_manager.go +++ b/lntest/harness_node_manager.go @@ -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, diff --git a/lntest/harness_setup.go b/lntest/harness_setup.go index 20442f9c2..61eac5d2f 100644 --- a/lntest/harness_setup.go +++ b/lntest/harness_setup.go @@ -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...") diff --git a/lntest/node/config.go b/lntest/node/config.go index 449ad2fad..1573af42e 100644 --- a/lntest/node/config.go +++ b/lntest/node/config.go @@ -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 != "" { diff --git a/make/testing_flags.mk b/make/testing_flags.mk index 68afc9aa0..df20cdb7e 100644 --- a/make/testing_flags.mk +++ b/make/testing_flags.mk @@ -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