From a7218e84eaa74d608d2884df75a829de015a9804 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 18 Aug 2017 18:22:54 -0600 Subject: [PATCH] lnd_test: reverse the order of teardown for lnd and btcd harnesses This commit prevents the case where btcd stops before lnd is fully started, thus making lnd_test hang on trying to stop lnd using `StopDaemon`. The underlying issue is that while lnd is trying to start the server and subscribe to block notifications from btcd, btcd stops, and lnd continues to attempt to reconnect before it ever starts the interrupt handler. This reversal avoids that issue by making sure lnd is stopped before btcd. --- lnd_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index a3857790..3ec157de 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -3128,7 +3128,19 @@ func TestLightningNetworkDaemon(t *testing.T) { if err != nil { ht.Fatalf("unable to create lightning network harness: %v", err) } - defer lndHarness.TearDownAll() + + // Set up teardowns. While it's easier to set up the lnd harness before + // the btcd harness, they should be torn down in reverse order to + // prevent certain types of hangs. + var btcdHarness *rpctest.Harness + defer func() { + if lndHarness != nil { + lndHarness.TearDownAll() + } + if btcdHarness != nil { + btcdHarness.TearDown() + } + }() handlers := &btcrpcclient.NotificationHandlers{ OnTxAccepted: lndHarness.OnTxAccepted, @@ -3157,11 +3169,10 @@ func TestLightningNetworkDaemon(t *testing.T) { // Transactions on the lightning network should always be standard to get // better guarantees of getting included in to blocks. args := []string{"--rejectnonstd"} - btcdHarness, err := rpctest.New(harnessNetParams, handlers, args) + btcdHarness, err = rpctest.New(harnessNetParams, handlers, args) if err != nil { ht.Fatalf("unable to create mining node: %v", err) } - defer btcdHarness.TearDown() // Turn off the btcd rpc logging, otherwise it will lead to panic. // TODO(andrew.shvv|roasbeef) Remove the hack after re-work the way the log