Skip to content

Commit 9131690

Browse files
authored
Merge pull request #546 from ViktorTigerstrom/2023-05-export-itest-structs
itest: export `ServerHarness` and `HarnessNode`
2 parents 8eb5372 + b398205 commit 9131690

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

itest/litd_node.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ var _ lnrpc.LightningClient = (*HarnessNode)(nil)
339339
var _ lnrpc.WalletUnlockerClient = (*HarnessNode)(nil)
340340
var _ invoicesrpc.InvoicesClient = (*HarnessNode)(nil)
341341

342-
// newNode creates a new test lightning node instance from the passed config.
343-
func newNode(t *testing.T, cfg *LitNodeConfig,
344-
harness *NetworkHarness) (*HarnessNode, error) {
342+
// NewNode creates a new test lightning node instance from the passed config.
343+
func NewNode(t *testing.T, cfg *LitNodeConfig,
344+
harness *lntest.HarnessTest) (*HarnessNode, error) {
345345

346346
if cfg.BaseDir == "" {
347347
var err error
@@ -393,7 +393,7 @@ func newNode(t *testing.T, cfg *LitNodeConfig,
393393

394394
var remoteNode *node.HarnessNode
395395
if cfg.RemoteMode {
396-
lndHarness := harness.LNDHarness
396+
lndHarness := harness
397397

398398
remoteNode = lndHarness.NewNode("bob-custom", cfg.ExtraArgs)
399399
tenBTC := btcutil.Amount(10 * btcutil.SatoshiPerBitcoin)
@@ -538,7 +538,7 @@ func renameFile(fromFileName, toFileName string) {
538538
//
539539
// This may not clean up properly if an error is returned, so the caller should
540540
// call shutdown() regardless of the return value.
541-
func (hn *HarnessNode) start(litdBinary string, litdError chan<- error,
541+
func (hn *HarnessNode) Start(litdBinary string, litdError chan<- error,
542542
wait bool, litArgOpts ...LitArgOption) error {
543543

544544
hn.quit = make(chan struct{})
@@ -1165,8 +1165,8 @@ func (hn *HarnessNode) cleanup() error {
11651165
return os.RemoveAll(hn.Cfg.BaseDir)
11661166
}
11671167

1168-
// Stop attempts to stop the active litd process.
1169-
func (hn *HarnessNode) stop() error {
1168+
// Stop attempts to Stop the active litd process.
1169+
func (hn *HarnessNode) Stop() error {
11701170
// Do nothing if the process is not running.
11711171
if hn.processExit == nil {
11721172
return nil
@@ -1246,7 +1246,7 @@ func (hn *HarnessNode) stop() error {
12461246
// shutdown stops the active lnd process and cleans up any temporary directories
12471247
// created along the way.
12481248
func (hn *HarnessNode) shutdown() error {
1249-
if err := hn.stop(); err != nil {
1249+
if err := hn.Stop(); err != nil {
12501250
return err
12511251
}
12521252
if err := hn.cleanup(); err != nil {

itest/network_harness.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type NetworkHarness struct {
4949
LNDHarness *lntest.HarnessTest
5050

5151
// server is an instance of the local Loop/Pool mock server.
52-
server *serverHarness
52+
server *ServerHarness
5353

5454
// BackendCfg houses the information necessary to use a node as LND
5555
// chain backend, such as rpc configuration, P2P information etc.
@@ -130,8 +130,8 @@ func (n *NetworkHarness) SetUp(t *testing.T,
130130
mockServerAddr := fmt.Sprintf(
131131
node.ListenerFormat, node.NextAvailablePort(),
132132
)
133-
n.server = newServerHarness(mockServerAddr)
134-
err := n.server.start()
133+
n.server = NewServerHarness(mockServerAddr)
134+
err := n.server.Start()
135135
require.NoError(t, err)
136136

137137
// Start a mock autopilot server.
@@ -273,10 +273,10 @@ func (n *NetworkHarness) NewNode(t *testing.T, name string, extraArgs []string,
273273
remoteMode bool, wait bool) (*HarnessNode, error) {
274274

275275
litArgs := []string{
276-
fmt.Sprintf("--loop.server.host=%s", n.server.serverHost),
277-
fmt.Sprintf("--loop.server.tlspath=%s", n.server.certFile),
278-
fmt.Sprintf("--pool.auctionserver=%s", n.server.serverHost),
279-
fmt.Sprintf("--pool.tlspathauctserver=%s", n.server.certFile),
276+
fmt.Sprintf("--loop.server.host=%s", n.server.ServerHost),
277+
fmt.Sprintf("--loop.server.tlspath=%s", n.server.CertFile),
278+
fmt.Sprintf("--pool.auctionserver=%s", n.server.ServerHost),
279+
fmt.Sprintf("--pool.tlspathauctserver=%s", n.server.CertFile),
280280
"--autopilot.insecure",
281281
fmt.Sprintf(
282282
"--autopilot.address=localhost:%d",
@@ -315,7 +315,7 @@ func (n *NetworkHarness) newNode(t *testing.T, name string, extraArgs,
315315
RemoteMode: remoteMode,
316316
}
317317

318-
node, err := newNode(t, cfg, n)
318+
node, err := NewNode(t, cfg, n.LNDHarness)
319319
if err != nil {
320320
return nil, err
321321
}
@@ -326,7 +326,7 @@ func (n *NetworkHarness) newNode(t *testing.T, name string, extraArgs,
326326
n.activeNodes[node.NodeID] = node
327327
n.mtx.Unlock()
328328

329-
err = node.start(n.litdBinary, n.lndErrorChan, wait)
329+
err = node.Start(n.litdBinary, n.lndErrorChan, wait)
330330
if err != nil {
331331
return nil, err
332332
}
@@ -649,7 +649,7 @@ func (n *NetworkHarness) RestartNode(node *HarnessNode, callback func() error,
649649
func (n *NetworkHarness) RestartNodeNoUnlock(node *HarnessNode,
650650
callback func() error, wait bool, litArgOpts ...LitArgOption) error {
651651

652-
if err := node.stop(); err != nil {
652+
if err := node.Stop(); err != nil {
653653
return err
654654
}
655655

@@ -659,18 +659,18 @@ func (n *NetworkHarness) RestartNodeNoUnlock(node *HarnessNode,
659659
}
660660
}
661661

662-
return node.start(n.litdBinary, n.lndErrorChan, wait, litArgOpts...)
662+
return node.Start(n.litdBinary, n.lndErrorChan, wait, litArgOpts...)
663663
}
664664

665665
// SuspendNode stops the given node and returns a callback that can be used to
666666
// start it again.
667667
func (n *NetworkHarness) SuspendNode(node *HarnessNode) (func() error, error) {
668-
if err := node.stop(); err != nil {
668+
if err := node.Stop(); err != nil {
669669
return nil, err
670670
}
671671

672672
restart := func() error {
673-
return node.start(n.litdBinary, n.lndErrorChan, true)
673+
return node.Start(n.litdBinary, n.lndErrorChan, true)
674674
}
675675

676676
return restart, nil
@@ -701,7 +701,7 @@ func (n *NetworkHarness) KillNode(node *HarnessNode) error {
701701
// This can be used to temporarily bring a node down during a test, to be later
702702
// started up again.
703703
func (n *NetworkHarness) StopNode(node *HarnessNode) error {
704-
return node.stop()
704+
return node.Stop()
705705
}
706706

707707
// OpenChannel attempts to open a channel between srcNode and destNode with the

itest/server_harness.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,47 @@ type loopPoolServer struct {
2727
swapserverrpc.UnimplementedSwapServerServer
2828
}
2929

30-
type serverHarness struct {
31-
serverHost string
30+
type ServerHarness struct {
31+
ServerHost string
3232
mockServer *grpc.Server
3333

34-
certFile string
34+
CertFile string
3535
server *loopPoolServer
3636

3737
errChan chan error
3838

3939
wg sync.WaitGroup
4040
}
4141

42-
func newServerHarness(serverHost string) *serverHarness {
43-
return &serverHarness{
44-
serverHost: serverHost,
42+
// NewServerHarness creates a new ServerHarness instance.
43+
func NewServerHarness(serverHost string) *ServerHarness {
44+
return &ServerHarness{
45+
ServerHost: serverHost,
4546
errChan: make(chan error, 1),
4647
}
4748
}
4849

49-
func (s *serverHarness) stop() {
50+
// Stop stops the mock Loop/Pool server.
51+
func (s *ServerHarness) Stop() {
5052
s.mockServer.Stop()
5153
s.wg.Wait()
5254
}
5355

54-
func (s *serverHarness) start() error {
56+
// Start starts the mock Loop/Pool server.
57+
func (s *ServerHarness) Start() error {
5558
tempDirName, err := ioutil.TempDir("", "litditest")
5659
if err != nil {
5760
return err
5861
}
5962

60-
s.certFile = filepath.Join(tempDirName, "proxy.cert")
63+
s.CertFile = filepath.Join(tempDirName, "proxy.cert")
6164
keyFile := filepath.Join(tempDirName, "proxy.key")
62-
creds, err := genCertPair(s.certFile, keyFile)
65+
creds, err := genCertPair(s.CertFile, keyFile)
6366
if err != nil {
6467
return err
6568
}
6669

67-
httpListener, err := net.Listen("tcp", s.serverHost)
70+
httpListener, err := net.Listen("tcp", s.ServerHost)
6871
if err != nil {
6972
return err
7073
}

0 commit comments

Comments
 (0)