Skip to content

Commit 81532ac

Browse files
committed
itest: add option for node upgrade/downgrade when suspending
1 parent abe90bc commit 81532ac

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

itest/network_harness.go

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,64 @@ func (n *NetworkHarness) RestartNodeNoUnlock(node *HarnessNode,
775775
)
776776
}
777777

778+
// suspendCfg contains any configurations related to suspending a node. This may
779+
// change the way the node starts up again.
780+
type suspendCfg struct {
781+
upgrade bool
782+
downgrade string
783+
}
784+
785+
// SuspendOption is a functional option that may change the suspend
786+
// configuration.
787+
type SuspendOption func(cfg *suspendCfg)
788+
789+
// WithUpgrade is a functional option which indicates that the node should be
790+
// upgraded to the latest version of LiT.
791+
func WithUpgrade() SuspendOption {
792+
return func(cfg *suspendCfg) {
793+
cfg.upgrade = true
794+
}
795+
}
796+
797+
// WithDowngrade is a functional option which indicates that the node should be
798+
// downgraded to the defined LiT version.
799+
func WithDowngrade(version string) SuspendOption {
800+
return func(cfg *suspendCfg) {
801+
cfg.downgrade = version
802+
}
803+
}
804+
778805
// SuspendNode stops the given node and returns a callback that can be used to
779-
// start it again.
780-
func (n *NetworkHarness) SuspendNode(node *HarnessNode) (func() error, error) {
806+
// start it again. If the upgrade flag is set then any backwards compatibility
807+
// version that the node was running previously will be eliminated, forcing it
808+
// to use the current (latest) build.
809+
func (n *NetworkHarness) SuspendNode(node *HarnessNode,
810+
opts ...SuspendOption) (func() error, error) {
811+
781812
if err := node.Stop(); err != nil {
782813
return nil, err
783814
}
784815

816+
cfg := &suspendCfg{}
817+
818+
for _, opt := range opts {
819+
opt(cfg)
820+
}
821+
822+
// If the upgrade flag was set delete any entry from the backwards
823+
// compatibility map. This will force the node to use the latest build
824+
// of LiT.
825+
if cfg.upgrade {
826+
delete(n.backwardCompat, node.Name())
827+
}
828+
829+
// If a downgrade version was defined update the backwards compatibility
830+
// entry with that version for this LiT node. This will force the node
831+
// to start up using the defined version.
832+
if cfg.downgrade != "" {
833+
n.backwardCompat[node.Name()] = cfg.downgrade
834+
}
835+
785836
restart := func() error {
786837
return node.Start(
787838
n.litdBinary, n.backwardCompat, n.lndErrorChan, true,
@@ -820,8 +871,10 @@ func (n *NetworkHarness) StopNode(node *HarnessNode) error {
820871
}
821872

822873
// StopAndBackupDB backs up the database of the target node.
823-
func (n *NetworkHarness) StopAndBackupDB(node *HarnessNode) error {
824-
restart, err := n.SuspendNode(node)
874+
func (n *NetworkHarness) StopAndBackupDB(node *HarnessNode,
875+
opts ...SuspendOption) error {
876+
877+
restart, err := n.SuspendNode(node, opts...)
825878
if err != nil {
826879
return err
827880
}
@@ -845,8 +898,10 @@ func (n *NetworkHarness) StopAndBackupDB(node *HarnessNode) error {
845898

846899
// StopAndRestoreDB stops the target node, restores the database from a backup
847900
// and starts the node again.
848-
func (n *NetworkHarness) StopAndRestoreDB(node *HarnessNode) error {
849-
restart, err := n.SuspendNode(node)
901+
func (n *NetworkHarness) StopAndRestoreDB(node *HarnessNode,
902+
opts ...SuspendOption) error {
903+
904+
restart, err := n.SuspendNode(node, opts...)
850905
if err != nil {
851906
return err
852907
}

0 commit comments

Comments
 (0)