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.
This commit is contained in:
Oliver Gugger
2021-09-29 10:12:25 +02:00
committed by Olaoluwa Osuntokun
parent aac824d6ef
commit 7aa9661d42

View File

@ -28,6 +28,7 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc/grpclog" "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 // Start the initial seeder nodes within the test network, then connect
// their respective RPC clients. // their respective RPC clients.
var wg sync.WaitGroup eg := errgroup.Group{}
wg.Add(2) eg.Go(func() error {
go func() { var err error
defer wg.Done() n.Alice, err = n.newNode(
n.Alice = n.NewNode(t, "Alice", lndArgs) "Alice", lndArgs, false, nil, n.dbBackend, true,
}() )
go func() { return err
defer wg.Done() })
n.Bob = n.NewNode(t, "Bob", lndArgs) eg.Go(func() error {
}() var err error
wg.Wait() 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 // First, make a connection between the two nodes. This will wait until
// both nodes are fully started since the Connect RPC is guarded behind // both nodes are fully started since the Connect RPC is guarded behind