Skip to content

Commit 7bb2a5b

Browse files
committed
itest: preparations for testing disabled sub-servers
1 parent a9fc614 commit 7bb2a5b

File tree

1 file changed

+77
-29
lines changed

1 file changed

+77
-29
lines changed

itest/litd_node.go

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/btcsuite/btcd/chaincfg/chainhash"
2525
"github.com/btcsuite/btcd/wire"
2626
"github.com/lightninglabs/faraday/frdrpc"
27+
terminal "github.com/lightninglabs/lightning-terminal"
2728
"github.com/lightninglabs/lightning-terminal/litrpc"
2829
"github.com/lightninglabs/loop/looprpc"
2930
"github.com/lightninglabs/pool/poolrpc"
@@ -62,7 +63,8 @@ var (
6263
type LitNodeConfig struct {
6364
*node.BaseNodeConfig
6465

65-
LitArgs []string
66+
LitArgs []string
67+
ActiveArgs *litArgs
6668

6769
RemoteMode bool
6870

@@ -129,6 +131,19 @@ func (l *litArgs) addArg(name, value string) {
129131
l.args[name] = value
130132
}
131133

134+
// getArg gets the arg with the given name from the set and returns the value.
135+
// The boolean returned will be true if the argument is in the set. If the
136+
// boolean is true but the string is empty, it means it is a boolean config
137+
// flag.
138+
func (l *litArgs) getArg(name string) (string, bool) {
139+
l.mu.Lock()
140+
defer l.mu.Unlock()
141+
142+
value, ok := l.args[name]
143+
144+
return value, ok
145+
}
146+
132147
// toArgList converts the litArgs map to an arguments string slice.
133148
func (l *litArgs) toArgList() []string {
134149
l.mu.Lock()
@@ -175,6 +190,8 @@ func (cfg *LitNodeConfig) GenArgs(opts ...LitArgOption) []string {
175190
opt(args)
176191
}
177192

193+
cfg.ActiveArgs = args
194+
178195
return args.toArgList()
179196
}
180197

@@ -539,7 +556,7 @@ func renameFile(fromFileName, toFileName string) {
539556
// This may not clean up properly if an error is returned, so the caller should
540557
// call shutdown() regardless of the return value.
541558
func (hn *HarnessNode) start(litdBinary string, litdError chan<- error,
542-
wait bool, litArgOpts ...LitArgOption) error {
559+
waitForStart bool, litArgOpts ...LitArgOption) error {
543560

544561
hn.quit = make(chan struct{})
545562

@@ -640,7 +657,7 @@ func (hn *HarnessNode) start(litdBinary string, litdError chan<- error,
640657

641658
// We may want to skip waiting for the node to come up (eg. the node
642659
// is waiting to become the leader).
643-
if !wait {
660+
if !waitForStart {
644661
return nil
645662
}
646663

@@ -681,7 +698,16 @@ func (hn *HarnessNode) start(litdBinary string, litdError chan<- error,
681698
}
682699
hn.litConn = litConn
683700

684-
return nil
701+
ctxt, cancel := context.WithTimeout(
702+
context.Background(), lntest.DefaultTimeout,
703+
)
704+
defer cancel()
705+
return wait.NoError(func() error {
706+
litConn := litrpc.NewProxyClient(hn.litConn)
707+
708+
_, err = litConn.GetInfo(ctxt, &litrpc.GetInfoRequest{})
709+
return err
710+
}, lntest.DefaultTimeout)
685711
}
686712

687713
// WaitUntilStarted waits until the wallet state flips from "WAITING_TO_START".
@@ -695,39 +721,53 @@ func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
695721
return err
696722
}
697723

724+
faradayMode, _ := hn.Cfg.ActiveArgs.getArg("faraday-mode")
725+
loopMode, _ := hn.Cfg.ActiveArgs.getArg("faraday-mode")
726+
poolMode, _ := hn.Cfg.ActiveArgs.getArg("faraday-mode")
727+
698728
ctxt, cancel := context.WithTimeout(context.Background(), timeout)
699729
defer cancel()
700730
return wait.NoError(func() error {
701-
faradayClient, err := hn.faradayClient()
702-
if err != nil {
703-
return err
704-
}
731+
if faradayMode != terminal.ModeDisable {
732+
faradayClient, err := hn.faradayClient()
733+
if err != nil {
734+
return err
735+
}
705736

706-
_, err = faradayClient.RevenueReport(
707-
ctxt, &frdrpc.RevenueReportRequest{},
708-
)
709-
if err != nil {
710-
return err
737+
_, err = faradayClient.RevenueReport(
738+
ctxt, &frdrpc.RevenueReportRequest{},
739+
)
740+
if err != nil {
741+
return err
742+
}
711743
}
712744

713-
loopClient, err := hn.loopClient()
714-
if err != nil {
715-
return err
716-
}
745+
if loopMode != terminal.ModeDisable {
746+
loopClient, err := hn.loopClient()
747+
if err != nil {
748+
return err
749+
}
717750

718-
_, err = loopClient.ListSwaps(ctxt, &looprpc.ListSwapsRequest{})
719-
if err != nil {
720-
return err
751+
_, err = loopClient.ListSwaps(
752+
ctxt, &looprpc.ListSwapsRequest{},
753+
)
754+
if err != nil {
755+
return err
756+
}
721757
}
722758

723-
poolClient, err := hn.poolClient()
724-
if err != nil {
725-
return err
726-
}
759+
if poolMode != terminal.ModeDisable {
760+
poolClient, err := hn.poolClient()
761+
if err != nil {
762+
return err
763+
}
727764

728-
_, err = poolClient.GetInfo(ctxt, &poolrpc.GetInfoRequest{})
729-
if err != nil {
730-
return err
765+
_, err = poolClient.GetInfo(
766+
ctxt, &poolrpc.GetInfoRequest{},
767+
)
768+
if err != nil {
769+
return err
770+
}
731771
}
732772

733773
return nil
@@ -788,9 +828,17 @@ func (hn *HarnessNode) waitForState(conn grpc.ClientConnInterface,
788828
ctx, cancel := context.WithCancel(context.Background())
789829
defer cancel()
790830

791-
stateStream, err := stateClient.SubscribeState(
792-
ctx, &lnrpc.SubscribeStateRequest{},
831+
var (
832+
stateStream lnrpc.State_SubscribeStateClient
833+
err error
793834
)
835+
err = wait.NoError(func() error {
836+
stateStream, err = stateClient.SubscribeState(
837+
ctx, &lnrpc.SubscribeStateRequest{},
838+
)
839+
840+
return err
841+
}, lntest.DefaultTimeout)
794842
if err != nil {
795843
return err
796844
}

0 commit comments

Comments
 (0)