From 7aa9661d42f79e3b9aeb85d67e70b75c577750bb Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 29 Sep 2021 10:12:25 +0200 Subject: [PATCH] lntest: use errgroup for node startup This commit fixes a nil pointer issue when a node fails to start up. Because require.NoErrorf() doesn't abort a test immediately if run inside a goroutine, this lead to the test continuing with nil node references which lead to a panic later on. --- lntest/harness.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index 1b03a4ef6..485a2b9af 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -28,6 +28,7 @@ import ( "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwire" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" "google.golang.org/grpc/grpclog" ) @@ -163,17 +164,22 @@ func (n *NetworkHarness) SetUp(t *testing.T, // Start the initial seeder nodes within the test network, then connect // their respective RPC clients. - var wg sync.WaitGroup - wg.Add(2) - go func() { - defer wg.Done() - n.Alice = n.NewNode(t, "Alice", lndArgs) - }() - go func() { - defer wg.Done() - n.Bob = n.NewNode(t, "Bob", lndArgs) - }() - wg.Wait() + eg := errgroup.Group{} + eg.Go(func() error { + var err error + n.Alice, err = n.newNode( + "Alice", lndArgs, false, nil, n.dbBackend, true, + ) + return err + }) + eg.Go(func() error { + var err error + n.Bob, err = n.newNode( + "Bob", lndArgs, false, nil, n.dbBackend, true, + ) + return err + }) + require.NoError(t, eg.Wait()) // First, make a connection between the two nodes. This will wait until // both nodes are fully started since the Connect RPC is guarded behind