mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
itest: make use of session ttl in failover test
This commit is contained in:
parent
7c8093ad1a
commit
0e4d7cf143
@ -275,7 +275,9 @@ func (n *NetworkHarness) Stop() {
|
|||||||
|
|
||||||
// extraArgsEtcd returns extra args for configuring LND to use an external etcd
|
// extraArgsEtcd returns extra args for configuring LND to use an external etcd
|
||||||
// database (for remote channel DB and wallet DB).
|
// database (for remote channel DB and wallet DB).
|
||||||
func extraArgsEtcd(etcdCfg *etcd.Config, name string, cluster bool) []string {
|
func extraArgsEtcd(etcdCfg *etcd.Config, name string, cluster bool,
|
||||||
|
leaderSessionTTL int) []string {
|
||||||
|
|
||||||
extraArgs := []string{
|
extraArgs := []string{
|
||||||
"--db.backend=etcd",
|
"--db.backend=etcd",
|
||||||
fmt.Sprintf("--db.etcd.host=%v", etcdCfg.Host),
|
fmt.Sprintf("--db.etcd.host=%v", etcdCfg.Host),
|
||||||
@ -289,10 +291,13 @@ func extraArgsEtcd(etcdCfg *etcd.Config, name string, cluster bool) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cluster {
|
if cluster {
|
||||||
extraArgs = append(extraArgs, "--cluster.enable-leader-election")
|
clusterArgs := []string{
|
||||||
extraArgs = append(
|
"--cluster.enable-leader-election",
|
||||||
extraArgs, fmt.Sprintf("--cluster.id=%v", name),
|
fmt.Sprintf("--cluster.id=%v", name),
|
||||||
)
|
fmt.Sprintf("--cluster.leader-session-ttl=%v",
|
||||||
|
leaderSessionTTL),
|
||||||
|
}
|
||||||
|
extraArgs = append(extraArgs, clusterArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return extraArgs
|
return extraArgs
|
||||||
@ -302,13 +307,13 @@ func extraArgsEtcd(etcdCfg *etcd.Config, name string, cluster bool) []string {
|
|||||||
// etcd database as its (remote) channel and wallet DB. The passsed cluster
|
// etcd database as its (remote) channel and wallet DB. The passsed cluster
|
||||||
// flag indicates that we'd like the node to join the cluster leader election.
|
// flag indicates that we'd like the node to join the cluster leader election.
|
||||||
func (n *NetworkHarness) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config,
|
func (n *NetworkHarness) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config,
|
||||||
password []byte, entropy []byte, statelessInit, cluster bool) (
|
password []byte, entropy []byte, statelessInit, cluster bool,
|
||||||
*HarnessNode, []string, []byte, error) {
|
leaderSessionTTL int) (*HarnessNode, []string, []byte, error) {
|
||||||
|
|
||||||
// We don't want to use the embedded etcd instance.
|
// We don't want to use the embedded etcd instance.
|
||||||
const dbBackend = BackendBbolt
|
const dbBackend = BackendBbolt
|
||||||
|
|
||||||
extraArgs := extraArgsEtcd(etcdCfg, name, cluster)
|
extraArgs := extraArgsEtcd(etcdCfg, name, cluster, leaderSessionTTL)
|
||||||
return n.newNodeWithSeed(
|
return n.newNodeWithSeed(
|
||||||
name, extraArgs, password, entropy, statelessInit, dbBackend,
|
name, extraArgs, password, entropy, statelessInit, dbBackend,
|
||||||
)
|
)
|
||||||
@ -320,12 +325,13 @@ func (n *NetworkHarness) NewNodeWithSeedEtcd(name string, etcdCfg *etcd.Config,
|
|||||||
// If the wait flag is false then we won't wait until RPC is available (this is
|
// If the wait flag is false then we won't wait until RPC is available (this is
|
||||||
// useful when the node is not expected to become the leader right away).
|
// useful when the node is not expected to become the leader right away).
|
||||||
func (n *NetworkHarness) NewNodeEtcd(name string, etcdCfg *etcd.Config,
|
func (n *NetworkHarness) NewNodeEtcd(name string, etcdCfg *etcd.Config,
|
||||||
password []byte, cluster, wait bool) (*HarnessNode, error) {
|
password []byte, cluster, wait bool, leaderSessionTTL int) (
|
||||||
|
*HarnessNode, error) {
|
||||||
|
|
||||||
// We don't want to use the embedded etcd instance.
|
// We don't want to use the embedded etcd instance.
|
||||||
const dbBackend = BackendBbolt
|
const dbBackend = BackendBbolt
|
||||||
|
|
||||||
extraArgs := extraArgsEtcd(etcdCfg, name, cluster)
|
extraArgs := extraArgsEtcd(etcdCfg, name, cluster, leaderSessionTTL)
|
||||||
return n.newNode(name, extraArgs, true, password, dbBackend, wait)
|
return n.newNode(name, extraArgs, true, password, dbBackend, wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,12 +81,15 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
|||||||
}
|
}
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
|
// Make leader election session TTL 5 sec to make the test run fast.
|
||||||
|
const leaderSessionTTL = 5
|
||||||
|
|
||||||
observer, err := cluster.MakeLeaderElector(
|
observer, err := cluster.MakeLeaderElector(
|
||||||
ctxb, cluster.EtcdLeaderElector, "observer",
|
ctxb, cluster.EtcdLeaderElector, "observer",
|
||||||
lncfg.DefaultEtcdElectionPrefix, etcdCfg,
|
lncfg.DefaultEtcdElectionPrefix, leaderSessionTTL, etcdCfg,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("Cannot start election observer")
|
ht.Fatalf("Cannot start election observer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
password := []byte("the quick brown fox jumps the lazy dog")
|
password := []byte("the quick brown fox jumps the lazy dog")
|
||||||
@ -96,6 +99,7 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
|||||||
|
|
||||||
carol1, _, _, err := net.NewNodeWithSeedEtcd(
|
carol1, _, _, err := net.NewNodeWithSeedEtcd(
|
||||||
"Carol-1", etcdCfg, password, entropy[:], stateless, cluster,
|
"Carol-1", etcdCfg, password, entropy[:], stateless, cluster,
|
||||||
|
leaderSessionTTL,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("unable to start Carol-1: %v", err)
|
ht.Fatalf("unable to start Carol-1: %v", err)
|
||||||
@ -122,7 +126,7 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
|||||||
// At this point Carol-1 is the elected leader, while Carol-2 will wait
|
// At this point Carol-1 is the elected leader, while Carol-2 will wait
|
||||||
// to become the leader when Carol-1 stops.
|
// to become the leader when Carol-1 stops.
|
||||||
carol2, err := net.NewNodeEtcd(
|
carol2, err := net.NewNodeEtcd(
|
||||||
"Carol-2", etcdCfg, password, cluster, false,
|
"Carol-2", etcdCfg, password, cluster, false, leaderSessionTTL,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("Unable to start Carol-2: %v", err)
|
ht.Fatalf("Unable to start Carol-2: %v", err)
|
||||||
@ -145,17 +149,14 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Shut down or kill Carol-1 and wait for Carol-2 to become the leader.
|
// Shut down or kill Carol-1 and wait for Carol-2 to become the leader.
|
||||||
var failoverTimeout time.Duration
|
failoverTimeout := time.Duration(2*leaderSessionTTL) * time.Second
|
||||||
if kill {
|
if kill {
|
||||||
err = net.KillNode(carol1)
|
err = net.KillNode(carol1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ht.Fatalf("Can't kill Carol-1: %v", err)
|
ht.Fatalf("Can't kill Carol-1: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
failoverTimeout = 2 * time.Minute
|
|
||||||
} else {
|
} else {
|
||||||
shutdownAndAssert(net, ht, carol1)
|
shutdownAndAssert(net, ht, carol1)
|
||||||
failoverTimeout = 30 * time.Second
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = carol2.WaitUntilLeader(failoverTimeout)
|
err = carol2.WaitUntilLeader(failoverTimeout)
|
||||||
|
Loading…
Reference in New Issue
Block a user