Skip to content

Commit

Permalink
lntest: use errgroup for node startup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guggero authored and Roasbeef committed Sep 30, 2021
1 parent aac824d commit 7aa9661
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7aa9661

Please sign in to comment.