test: speed up integration test harness initialization
This commit speeds up the integration test initialization by launching the processes of the two seeder nodes concurrently rather than serially. Additionally, the harness will now block until the wallets of both the seeder nodes are fully synced up.
This commit is contained in:
parent
d548e56069
commit
05ac8d3c47
@ -11,6 +11,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
@ -284,20 +285,40 @@ func (n *networkHarness) SetUp() error {
|
|||||||
|
|
||||||
// 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
|
||||||
|
errChan := make(chan error, 2)
|
||||||
|
wg.Add(2)
|
||||||
|
go func() {
|
||||||
var err error
|
var err error
|
||||||
if err := n.aliceNode.start(); err != nil {
|
defer wg.Done()
|
||||||
return err
|
if err = n.aliceNode.start(); err != nil {
|
||||||
}
|
errChan <- err
|
||||||
if err := n.bobNode.start(); err != nil {
|
return
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
n.AliceClient, err = initRpcClient(n.aliceNode.rpcAddr)
|
n.AliceClient, err = initRpcClient(n.aliceNode.rpcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
errChan <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
var err error
|
||||||
|
defer wg.Done()
|
||||||
|
if err = n.bobNode.start(); err != nil {
|
||||||
|
errChan <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
n.BobClient, err = initRpcClient(n.bobNode.rpcAddr)
|
n.BobClient, err = initRpcClient(n.bobNode.rpcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
errChan <- err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
wg.Wait()
|
||||||
|
select {
|
||||||
|
case err := <-errChan:
|
||||||
|
return err
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load up the wallets of the seeder nodes with 10 outputs of 1 BTC
|
// Load up the wallets of the seeder nodes with 10 outputs of 1 BTC
|
||||||
@ -351,6 +372,30 @@ func (n *networkHarness) SetUp() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now block until both wallets have fully synced up.
|
||||||
|
expectedBalance := btcutil.Amount(btcutil.SatoshiPerBitcoin * 10).ToBTC()
|
||||||
|
balReq := &lnrpc.WalletBalanceRequest{}
|
||||||
|
balanceTicker := time.Tick(time.Millisecond * 100)
|
||||||
|
out:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-balanceTicker:
|
||||||
|
aliceResp, err := n.AliceClient.WalletBalance(ctxb, balReq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bobResp, err := n.BobClient.WalletBalance(ctxb, balReq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if aliceResp.Balance == expectedBalance &&
|
||||||
|
bobResp.Balance == expectedBalance {
|
||||||
|
break out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +416,7 @@ func initRpcClient(serverAddr string) (lnrpc.LightningClient, error) {
|
|||||||
opts := []grpc.DialOption{
|
opts := []grpc.DialOption{
|
||||||
grpc.WithInsecure(),
|
grpc.WithInsecure(),
|
||||||
grpc.WithBlock(),
|
grpc.WithBlock(),
|
||||||
grpc.WithTimeout(time.Second * 10),
|
grpc.WithTimeout(time.Second * 20),
|
||||||
}
|
}
|
||||||
conn, err := grpc.Dial(serverAddr, opts...)
|
conn, err := grpc.Dial(serverAddr, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user