mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
test: ensure blocks are synchronized before opening channels, allow more time for sync payments
Fix bug with synchronizing blockchain by adding several retries. Allow to launch individual tests. Increase timeout for async payments. Fixes #213.
This commit is contained in:
parent
276a360353
commit
e324fe5818
3 changed files with 65 additions and 5 deletions
|
@ -504,6 +504,7 @@ func (f *fundingManager) handleFundingRequest(fmsg *fundingRequestMsg) {
|
||||||
fndgLog.Errorf("unable to query wallet: %v", err)
|
fndgLog.Errorf("unable to query wallet: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isSynced {
|
if !isSynced {
|
||||||
errMsg := &lnwire.Error{
|
errMsg := &lnwire.Error{
|
||||||
ChanID: fmsg.msg.PendingChannelID,
|
ChanID: fmsg.msg.PendingChannelID,
|
||||||
|
|
14
lnd_test.go
14
lnd_test.go
|
@ -82,7 +82,7 @@ func (h *harnessTest) RunTestCase(testCase *testCase, net *networkHarness) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
testCase.test(net, h)
|
testCase.test(net, h)
|
||||||
h.t.Logf("Passed: (%v)", h.testCase.name)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2823,15 +2823,16 @@ func testBidirectionalAsyncPayments(net *networkHarness, t *harnessTest) {
|
||||||
|
|
||||||
// Wait for Alice and Bob receive their payments, and throw and error
|
// Wait for Alice and Bob receive their payments, and throw and error
|
||||||
// if something goes wrong.
|
// if something goes wrong.
|
||||||
|
maxTime := 20 * time.Second
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second * 7):
|
case <-time.After(time.Second * maxTime):
|
||||||
t.Fatalf("waiting for payments to finish too long "+
|
t.Fatalf("waiting for payments to finish too long "+
|
||||||
"(7s)")
|
"(%v)", maxTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3038,7 +3039,14 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("Running %v integration tests", len(testsCases))
|
t.Logf("Running %v integration tests", len(testsCases))
|
||||||
for _, testCase := range testsCases {
|
for _, testCase := range testsCases {
|
||||||
|
success := t.Run(testCase.name, func(t1 *testing.T) {
|
||||||
|
ht := newHarnessTest(t1)
|
||||||
ht.RunTestCase(testCase, lndHarness)
|
ht.RunTestCase(testCase, lndHarness)
|
||||||
|
})
|
||||||
|
// Stop at the first failure. Mimic behavior of original test
|
||||||
|
if !success {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(testsFin)
|
close(testsFin)
|
||||||
|
|
|
@ -574,6 +574,41 @@ func (l *lightningNode) WaitForNetworkChannelClose(ctx context.Context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForBlockchainSync will block until node synchronizes its blockchain
|
||||||
|
func (l *lightningNode) WaitForBlockchainSync(ctx context.Context) error {
|
||||||
|
errChan := make(chan error, 1)
|
||||||
|
retryDelay := time.Millisecond * 100
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
getInfoReq := &lnrpc.GetInfoRequest{}
|
||||||
|
getInfoResp, err := l.GetInfo(ctx, getInfoReq)
|
||||||
|
if err != nil {
|
||||||
|
errChan <- err
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if getInfoResp.SyncedToChain {
|
||||||
|
errChan <- nil
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
break
|
||||||
|
case <-time.After(retryDelay):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case err := <-errChan:
|
||||||
|
return err
|
||||||
|
case <-ctx.Done():
|
||||||
|
return fmt.Errorf("Timeout while waiting for blockchain sync")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// networkHarness is an integration testing harness for the lightning network.
|
// networkHarness is an integration testing harness for the lightning network.
|
||||||
// The harness by default is created with two active nodes on the network:
|
// The harness by default is created with two active nodes on the network:
|
||||||
// Alice and Bob.
|
// Alice and Bob.
|
||||||
|
@ -972,6 +1007,14 @@ func (n *networkHarness) OpenChannel(ctx context.Context,
|
||||||
srcNode, destNode *lightningNode, amt btcutil.Amount,
|
srcNode, destNode *lightningNode, amt btcutil.Amount,
|
||||||
pushAmt btcutil.Amount, numConfs uint32) (lnrpc.Lightning_OpenChannelClient, error) {
|
pushAmt btcutil.Amount, numConfs uint32) (lnrpc.Lightning_OpenChannelClient, error) {
|
||||||
|
|
||||||
|
// Wait until srcNode and destNode have blockchain synced
|
||||||
|
if err := srcNode.WaitForBlockchainSync(ctx); err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to sync srcNode chain: %v", err)
|
||||||
|
}
|
||||||
|
if err := destNode.WaitForBlockchainSync(ctx); err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to sync destNode chain: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
openReq := &lnrpc.OpenChannelRequest{
|
openReq := &lnrpc.OpenChannelRequest{
|
||||||
NodePubkey: destNode.PubKey[:],
|
NodePubkey: destNode.PubKey[:],
|
||||||
LocalFundingAmount: int64(amt),
|
LocalFundingAmount: int64(amt),
|
||||||
|
@ -1024,6 +1067,14 @@ func (n *networkHarness) OpenPendingChannel(ctx context.Context,
|
||||||
srcNode, destNode *lightningNode, amt btcutil.Amount,
|
srcNode, destNode *lightningNode, amt btcutil.Amount,
|
||||||
pushAmt btcutil.Amount, numConfs uint32) (*lnrpc.PendingUpdate, error) {
|
pushAmt btcutil.Amount, numConfs uint32) (*lnrpc.PendingUpdate, error) {
|
||||||
|
|
||||||
|
// Wait until srcNode and destNode have blockchain synced
|
||||||
|
if err := srcNode.WaitForBlockchainSync(ctx); err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to sync srcNode chain: %v", err)
|
||||||
|
}
|
||||||
|
if err := destNode.WaitForBlockchainSync(ctx); err != nil {
|
||||||
|
return nil, fmt.Errorf("Unable to sync destNode chain: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
openReq := &lnrpc.OpenChannelRequest{
|
openReq := &lnrpc.OpenChannelRequest{
|
||||||
NodePubkey: destNode.PubKey[:],
|
NodePubkey: destNode.PubKey[:],
|
||||||
LocalFundingAmount: int64(amt),
|
LocalFundingAmount: int64(amt),
|
||||||
|
|
Loading…
Add table
Reference in a new issue