itest: add db backend flag
This commit is contained in:
parent
387f1ef274
commit
98e75b486d
@ -59,7 +59,7 @@ jobs:
|
||||
- name: Bitcoind Integration with etcd (txindex enabled)
|
||||
script:
|
||||
- bash ./scripts/install_bitcoind.sh
|
||||
- make itest-parallel backend=bitcoind etcd=1
|
||||
- make itest-parallel backend=bitcoind dbbackend=etcd
|
||||
|
||||
- name: Bitcoind Integration (txindex disabled)
|
||||
script:
|
||||
|
@ -67,9 +67,8 @@ type NetworkHarness struct {
|
||||
Alice *HarnessNode
|
||||
Bob *HarnessNode
|
||||
|
||||
// embeddedEtcd is set to true if new nodes are to be created with an
|
||||
// embedded etcd backend instead of just bbolt.
|
||||
embeddedEtcd bool
|
||||
// dbBackend sets the database backend to use.
|
||||
dbBackend DatabaseBackend
|
||||
|
||||
// Channel for transmitting stderr output from failed lightning node
|
||||
// to main process.
|
||||
@ -84,12 +83,19 @@ type NetworkHarness struct {
|
||||
mtx sync.Mutex
|
||||
}
|
||||
|
||||
type DatabaseBackend int
|
||||
|
||||
const (
|
||||
BackendBbolt DatabaseBackend = iota
|
||||
BackendEtcd
|
||||
)
|
||||
|
||||
// NewNetworkHarness creates a new network test harness.
|
||||
// TODO(roasbeef): add option to use golang's build library to a binary of the
|
||||
// current repo. This will save developers from having to manually `go install`
|
||||
// within the repo each time before changes
|
||||
func NewNetworkHarness(r *rpctest.Harness, b BackendConfig, lndBinary string,
|
||||
embeddedEtcd bool) (*NetworkHarness, error) {
|
||||
dbBackend DatabaseBackend) (*NetworkHarness, error) {
|
||||
|
||||
feeService := startFeeService()
|
||||
|
||||
@ -103,7 +109,7 @@ func NewNetworkHarness(r *rpctest.Harness, b BackendConfig, lndBinary string,
|
||||
feeService: feeService,
|
||||
quit: make(chan struct{}),
|
||||
lndBinary: lndBinary,
|
||||
embeddedEtcd: embeddedEtcd,
|
||||
dbBackend: dbBackend,
|
||||
}
|
||||
return &n, nil
|
||||
}
|
||||
@ -306,11 +312,11 @@ func (n *NetworkHarness) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config,
|
||||
*HarnessNode, []string, []byte, error) {
|
||||
|
||||
// We don't want to use the embedded etcd instance.
|
||||
const embeddedEtcd = false
|
||||
const dbBackend = BackendBbolt
|
||||
|
||||
extraArgs := extraArgsEtcd(etcdCfg, name, cluster)
|
||||
return n.newNodeWithSeed(
|
||||
name, extraArgs, password, entropy, statelessInit, embeddedEtcd,
|
||||
name, extraArgs, password, entropy, statelessInit, dbBackend,
|
||||
)
|
||||
}
|
||||
|
||||
@ -323,10 +329,10 @@ func (n *NetworkHarness) NewNodeEtcd(name string, etcdCfg *etcd.Config,
|
||||
password []byte, cluster, wait bool) (*HarnessNode, error) {
|
||||
|
||||
// We don't want to use the embedded etcd instance.
|
||||
const embeddedEtcd = false
|
||||
const dbBackend = BackendBbolt
|
||||
|
||||
extraArgs := extraArgsEtcd(etcdCfg, name, cluster)
|
||||
return n.newNode(name, extraArgs, true, password, embeddedEtcd, wait)
|
||||
return n.newNode(name, extraArgs, true, password, dbBackend, wait)
|
||||
}
|
||||
|
||||
// NewNode fully initializes a returns a new HarnessNode bound to the
|
||||
@ -336,7 +342,7 @@ func (n *NetworkHarness) NewNode(t *testing.T,
|
||||
name string, extraArgs []string) *HarnessNode {
|
||||
|
||||
node, err := n.newNode(
|
||||
name, extraArgs, false, nil, n.embeddedEtcd, true,
|
||||
name, extraArgs, false, nil, n.dbBackend, true,
|
||||
)
|
||||
require.NoErrorf(t, err, "unable to create new node for %s", name)
|
||||
|
||||
@ -352,16 +358,16 @@ func (n *NetworkHarness) NewNodeWithSeed(name string, extraArgs []string,
|
||||
error) {
|
||||
|
||||
return n.newNodeWithSeed(
|
||||
name, extraArgs, password, nil, statelessInit, n.embeddedEtcd,
|
||||
name, extraArgs, password, nil, statelessInit, n.dbBackend,
|
||||
)
|
||||
}
|
||||
|
||||
func (n *NetworkHarness) newNodeWithSeed(name string, extraArgs []string,
|
||||
password, entropy []byte, statelessInit, embeddedEtcd bool) (
|
||||
password, entropy []byte, statelessInit bool, dbBackend DatabaseBackend) (
|
||||
*HarnessNode, []string, []byte, error) {
|
||||
|
||||
node, err := n.newNode(
|
||||
name, extraArgs, true, password, embeddedEtcd, true,
|
||||
name, extraArgs, true, password, dbBackend, true,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
@ -425,7 +431,7 @@ func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string,
|
||||
opts ...NodeOption) (*HarnessNode, error) {
|
||||
|
||||
node, err := n.newNode(
|
||||
name, extraArgs, true, password, n.embeddedEtcd, true, opts...,
|
||||
name, extraArgs, true, password, n.dbBackend, true, opts...,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -456,7 +462,7 @@ func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string,
|
||||
// can be used immediately. Otherwise, the node will require an additional
|
||||
// initialization phase where the wallet is either created or restored.
|
||||
func (n *NetworkHarness) newNode(name string, extraArgs []string, hasSeed bool,
|
||||
password []byte, embeddedEtcd, wait bool, opts ...NodeOption) (
|
||||
password []byte, dbBackend DatabaseBackend, wait bool, opts ...NodeOption) (
|
||||
*HarnessNode, error) {
|
||||
|
||||
cfg := &NodeConfig{
|
||||
@ -468,7 +474,7 @@ func (n *NetworkHarness) newNode(name string, extraArgs []string, hasSeed bool,
|
||||
NetParams: n.netParams,
|
||||
ExtraArgs: extraArgs,
|
||||
FeeURL: n.feeService.url,
|
||||
Etcd: embeddedEtcd,
|
||||
DbBackend: dbBackend,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(cfg)
|
||||
|
@ -80,8 +80,8 @@ var (
|
||||
"split test cases with the given (0-based) index",
|
||||
)
|
||||
|
||||
// useEtcd test LND nodes use (embedded) etcd as remote db.
|
||||
useEtcd = flag.Bool("etcd", false, "Use etcd backend for lnd.")
|
||||
// dbBackendFlag specifies the backend to use
|
||||
dbBackendFlag = flag.String("dbbackend", "bbolt", "Database backend (bbolt, etcd)")
|
||||
)
|
||||
|
||||
// getTestCaseSplitTranche returns the sub slice of the test cases that should
|
||||
@ -11573,12 +11573,25 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
||||
require.NoError(t, miner.Client.NotifyNewTransactions(false))
|
||||
require.NoError(t, chainBackend.ConnectMiner(), "connect miner")
|
||||
|
||||
// Parse database backend
|
||||
var dbBackend lntest.DatabaseBackend
|
||||
switch *dbBackendFlag {
|
||||
case "bbolt":
|
||||
dbBackend = lntest.BackendBbolt
|
||||
|
||||
case "etcd":
|
||||
dbBackend = lntest.BackendEtcd
|
||||
|
||||
default:
|
||||
require.Fail(t, "unknown db backend")
|
||||
}
|
||||
|
||||
// Now we can set up our test harness (LND instance), with the chain
|
||||
// backend we just created.
|
||||
ht := newHarnessTest(t, nil)
|
||||
binary := ht.getLndBinary()
|
||||
lndHarness, err = lntest.NewNetworkHarness(
|
||||
miner, chainBackend, binary, *useEtcd,
|
||||
miner, chainBackend, binary, dbBackend,
|
||||
)
|
||||
if err != nil {
|
||||
ht.Fatalf("unable to create lightning network harness: %v", err)
|
||||
|
@ -220,7 +220,7 @@ type NodeConfig struct {
|
||||
|
||||
FeeURL string
|
||||
|
||||
Etcd bool
|
||||
DbBackend DatabaseBackend
|
||||
}
|
||||
|
||||
func (cfg NodeConfig) P2PAddr() string {
|
||||
@ -308,7 +308,7 @@ func (cfg NodeConfig) genArgs() []string {
|
||||
args = append(args, "--accept-amp")
|
||||
}
|
||||
|
||||
if cfg.Etcd {
|
||||
if cfg.DbBackend == BackendEtcd {
|
||||
args = append(args, "--db.backend=etcd")
|
||||
args = append(args, "--db.etcd.embedded")
|
||||
args = append(
|
||||
|
@ -49,9 +49,12 @@ ifneq ($(icase),)
|
||||
TEST_FLAGS += -test.run="TestLightningNetworkDaemon/.*-of-.*/.*/$(icase)"
|
||||
endif
|
||||
|
||||
# Run itests with etcd backend.
|
||||
ifeq ($(etcd),1)
|
||||
ITEST_FLAGS += -etcd
|
||||
# Run itests with specified db backend.
|
||||
ifneq ($(dbbackend),)
|
||||
ITEST_FLAGS += -dbbackend=$(dbbackend)
|
||||
endif
|
||||
|
||||
ifeq ($(dbbackend),etcd)
|
||||
DEV_TAGS += kvdb_etcd
|
||||
endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user