lntest: Add ShutdownNode method to harness.

This is preferable to calling Shutdown on the node directly so that
the harness manages the entire lifecycle of an lnd process.
This commit is contained in:
Jim Posen 2017-11-03 14:40:57 -07:00 committed by Olaoluwa Osuntokun
parent 77d5f21b54
commit 19ed1fb8db
3 changed files with 25 additions and 14 deletions

View File

@ -917,7 +917,7 @@ peersPoll:
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
// Clean up carol's node.
if err := carol.Shutdown(); err != nil {
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}
}
@ -2218,13 +2218,13 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(ctxt, t, net, carol, chanPointCarol, false)
// Finally, shutdown the nodes we created for the duration of the
// tests, only leaving the two seed nodes (Alice and Bob) within our
// test network.
if err := carol.Shutdown(); err != nil {
// Finally, shutdown the nodes we created for the duration of the tests,
// only leaving the two seed nodes (Alice and Bob) within our test
// network.
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}
if err := dave.Shutdown(); err != nil {
if err := net.ShutdownNode(dave); err != nil {
t.Fatalf("unable to shutdown dave: %v", err)
}
}
@ -2456,7 +2456,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Finally, shutdown the node we created for the duration of the tests,
// only leaving the two seed nodes (Alice and Bob) within our test
// network.
if err := carol.Shutdown(); err != nil {
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}
}
@ -3546,7 +3546,7 @@ out:
// We'll attempt to complete the original invoice we created with Carol
// above, but before we do so, Carol will go offline, resulting in a
// failed payment.
if err := carol.Shutdown(); err != nil {
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}
// TODO(roasbeef): mission control
@ -3804,7 +3804,7 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
close(quit)
// Finally, shutdown carol as our test has concluded successfully.
if err := carol.Shutdown(); err != nil {
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}
}
@ -3882,7 +3882,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ = context.WithTimeout(ctxb, timeout)
closeChannelAndAssert(ctxt, t, net, net.Bob, chanPoint, false)
if err := dave.Shutdown(); err != nil {
if err := net.ShutdownNode(dave); err != nil {
t.Fatalf("unable to shutdown dave: %v", err)
}
}
@ -3953,7 +3953,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) {
}
// Clean up carol's node.
if err := carol.Shutdown(); err != nil {
if err := net.ShutdownNode(carol); err != nil {
t.Fatalf("unable to shutdown carol: %v", err)
}

View File

@ -224,7 +224,7 @@ out:
// TearDownAll tears down all active nodes within the test lightning network.
func (n *NetworkHarness) TearDownAll() error {
for _, node := range n.activeNodes {
if err := node.Shutdown(); err != nil {
if err := n.ShutdownNode(node); err != nil {
return err
}
}
@ -341,6 +341,17 @@ func (n *NetworkHarness) RestartNode(node *HarnessNode, callback func() error) e
return node.restart(n.lndErrorChan, callback)
}
// ShutdownNode stops an active lnd process and returns when the process has
// exited and any temporary directories have been cleaned up.
func (n *NetworkHarness) ShutdownNode(node *HarnessNode) error {
if err := node.shutdown(); err != nil {
return err
}
delete(n.activeNodes, node.NodeID)
return nil
}
// TODO(roasbeef): add a WithChannel higher-order function?
// * python-like context manager w.r.t using a channel within a test
// * possibly adds more funds to the target wallet if the funds are not

View File

@ -415,9 +415,9 @@ func (hn *HarnessNode) restart(errChan chan error, callback func() error) error
return hn.start(errChan)
}
// Shutdown stops the active lnd process and clean up any temporary directories
// shutdown stops the active lnd process and cleans up any temporary directories
// created along the way.
func (hn *HarnessNode) Shutdown() error {
func (hn *HarnessNode) shutdown() error {
if err := hn.stop(); err != nil {
return err
}