Skip to content

Commit ba8e755

Browse files
committed
itest: add the -nativesql flag to run SQL itests with native SQL tables
1 parent 7a45bbb commit ba8e755

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

itest/lnd_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ var (
7171
dbBackendFlag = flag.String("dbbackend", "bbolt", "Database backend "+
7272
"(bbolt, etcd, postgres)")
7373

74+
nativeSQLFlag = flag.Bool("nativesql", false, "Database backend to "+
75+
"use native SQL when applicable (only for sqlite and postgres")
76+
7477
// lndExecutable is the full path to the lnd binary.
7578
lndExecutable = flag.String(
7679
"lndexec", itestLndBinary, "full path to lnd binary",
@@ -95,7 +98,7 @@ func TestLightningNetworkDaemon(t *testing.T) {
9598
// Get the binary path and setup the harness test.
9699
binary := getLndBinary(t)
97100
harnessTest := lntest.SetupHarness(
98-
t, binary, *dbBackendFlag, feeService,
101+
t, binary, *dbBackendFlag, *nativeSQLFlag, feeService,
99102
)
100103
defer harnessTest.Stop()
101104

lntest/harness.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ type HarnessTest struct {
103103
// NewHarnessTest creates a new instance of a harnessTest from a regular
104104
// testing.T instance.
105105
func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
106-
dbBackend node.DatabaseBackend) *HarnessTest {
106+
dbBackend node.DatabaseBackend, nativeSQL bool) *HarnessTest {
107107

108108
t.Helper()
109109

110110
// Create the run context.
111111
ctxt, cancel := context.WithCancel(context.Background())
112112

113-
manager := newNodeManager(lndBinary, dbBackend)
113+
manager := newNodeManager(lndBinary, dbBackend, nativeSQL)
114114

115115
return &HarnessTest{
116116
T: t,

lntest/harness_node_manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type nodeManager struct {
3131
// dbBackend sets the database backend to use.
3232
dbBackend node.DatabaseBackend
3333

34+
// nativeSQL sets the database backend to use native SQL when
35+
// applicable.
36+
nativeSQL bool
37+
3438
// activeNodes is a map of all running nodes, format:
3539
// {pubkey: *HarnessNode}.
3640
activeNodes map[uint32]*node.HarnessNode
@@ -48,12 +52,13 @@ type nodeManager struct {
4852
}
4953

5054
// newNodeManager creates a new node manager instance.
51-
func newNodeManager(lndBinary string,
52-
dbBackend node.DatabaseBackend) *nodeManager {
55+
func newNodeManager(lndBinary string, dbBackend node.DatabaseBackend,
56+
nativeSQL bool) *nodeManager {
5357

5458
return &nodeManager{
5559
lndBinary: lndBinary,
5660
dbBackend: dbBackend,
61+
nativeSQL: nativeSQL,
5762
activeNodes: make(map[uint32]*node.HarnessNode),
5863
standbyNodes: make(map[uint32]*node.HarnessNode),
5964
}
@@ -80,6 +85,7 @@ func (nm *nodeManager) newNode(t *testing.T, name string, extraArgs []string,
8085
ExtraArgs: extraArgs,
8186
FeeURL: nm.feeServiceURL,
8287
DBBackend: nm.dbBackend,
88+
NativeSQL: nm.nativeSQL,
8389
NodeID: nm.nextNodeID(),
8490
LndBinary: nm.lndBinary,
8591
NetParams: harnessNetParams,

lntest/harness_setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// 4. connect the miner and the chain backend.
1919
// 5. start the HarnessTest.
2020
func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
21-
feeService WebFeeService) *HarnessTest {
21+
nativeSQL bool, feeService WebFeeService) *HarnessTest {
2222

2323
t.Log("Setting up HarnessTest...")
2424

@@ -30,7 +30,7 @@ func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
3030
dbBackend := prepareDBBackend(t, dbBackendName)
3131

3232
// Create a new HarnessTest.
33-
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend)
33+
ht := NewHarnessTest(t, binaryPath, feeService, dbBackend, nativeSQL)
3434

3535
// Init the miner.
3636
t.Log("Prepare the miner and mine blocks to activate segwit...")

lntest/node/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type BaseNodeConfig struct {
119119

120120
DBBackend DatabaseBackend
121121
PostgresDsn string
122+
NativeSQL bool
122123

123124
// NodeID is a unique ID used to identify the node.
124125
NodeID uint32
@@ -277,11 +278,17 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
277278
case BackendPostgres:
278279
args = append(args, "--db.backend=postgres")
279280
args = append(args, "--db.postgres.dsn="+cfg.PostgresDsn)
281+
if cfg.NativeSQL {
282+
args = append(args, "--db.use-native-sql")
283+
}
280284

281285
case BackendSqlite:
282286
args = append(args, "--db.backend=sqlite")
283287
args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v",
284288
wait.SqliteBusyTimeout))
289+
if cfg.NativeSQL {
290+
args = append(args, "--db.use-native-sql")
291+
}
285292
}
286293

287294
if cfg.FeeURL != "" {

make/testing_flags.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ DEV_TAGS += kvdb_etcd
6060
endif
6161

6262
ifeq ($(dbbackend),postgres)
63+
ifneq ($(nativesql),)
64+
ITEST_FLAGS += -nativesql
65+
endif
6366
DEV_TAGS += kvdb_postgres
6467
endif
6568

6669
ifeq ($(dbbackend),sqlite)
70+
ifneq ($(nativesql),)
71+
ITEST_FLAGS += -nativesql
72+
endif
6773
DEV_TAGS += kvdb_sqlite
6874
endif
6975

0 commit comments

Comments
 (0)