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:
Olaoluwa Osuntokun 2016-08-30 16:44:47 -07:00
parent d548e56069
commit 05ac8d3c47
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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 err error var wg sync.WaitGroup
if err := n.aliceNode.start(); err != nil { errChan := make(chan error, 2)
wg.Add(2)
go func() {
var err error
defer wg.Done()
if err = n.aliceNode.start(); err != nil {
errChan <- err
return
}
n.AliceClient, err = initRpcClient(n.aliceNode.rpcAddr)
if err != 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)
if err != nil {
errChan <- err
return
}
}()
wg.Wait()
select {
case err := <-errChan:
return err return err
} default:
if err := n.bobNode.start(); err != nil {
return err
}
n.AliceClient, err = initRpcClient(n.aliceNode.rpcAddr)
if err != nil {
return nil
}
n.BobClient, err = initRpcClient(n.bobNode.rpcAddr)
if err != nil {
return nil
} }
// 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 {