lnd_test: use EnsureConnected in itests hot spots

Uses EnsureConnected when reconnecting nodes in:
 - switch offline delivery persistence
 - graph topology notifications
 - channel funding persistence
This commit is contained in:
Conner Fromknecht 2018-03-30 19:59:58 -07:00
parent 0449c0d50b
commit 517135dd9a
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

View File

@ -1147,24 +1147,8 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// The following block ensures that after both nodes have restarted,
// they have reconnected before the execution of the next test.
peersTimeout := time.After(15 * time.Second)
checkPeersTick := time.NewTicker(100 * time.Millisecond)
defer checkPeersTick.Stop()
peersPoll:
for {
select {
case <-peersTimeout:
t.Fatalf("peers unable to reconnect after restart")
case <-checkPeersTick.C:
peers, err := carol.ListPeers(ctxb,
&lnrpc.ListPeersRequest{})
if err != nil {
t.Fatalf("ListPeers error: %v\n", err)
}
if len(peers.Peers) > 0 {
break peersPoll
}
}
if err := net.EnsureConnected(ctxb, net.Alice, carol); err != nil {
t.Fatalf("peers unable to reconnect after restart: %v", err)
}
// Next, mine enough blocks s.t the channel will open with a single
@ -1251,6 +1235,11 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
}
}
// Before beginning, make sure alice and bob are connected.
if err := net.EnsureConnected(ctx, net.Alice, net.Bob); err != nil {
t.Fatalf("unable to connect alice and bob: %v", err)
}
chanPoint := openChannelAndAssert(ctx, t, net, net.Alice, net.Bob,
amount, 0)
@ -4610,7 +4599,7 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
// and Carol. Note that we will also receive a node announcement from
// Bob, since a node will update its node announcement after a new
// channel is opened.
if err := net.ConnectNodes(ctxb, net.Alice, net.Bob); err != nil {
if err := net.EnsureConnected(ctxb, net.Alice, net.Bob); err != nil {
t.Fatalf("unable to connect alice to bob: %v", err)
}
@ -7172,7 +7161,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Now that the settles have reached Dave, reconnect him with Alice,
// allowing the settles to return to the sender.
ctxt, _ = context.WithTimeout(ctxb, timeout)
if err := net.ConnectNodes(ctxt, dave, net.Alice); err != nil {
if err := net.EnsureConnected(ctxt, dave, net.Alice); err != nil {
t.Fatalf("unable to reconnect alice to dave: %v", err)
}
@ -7481,8 +7470,16 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
t.Fatalf("unable to reconnect alice to dave: %v", err)
}
// After Dave reconnects, the settles should be propagated all the way
// back to the sender. All nodes should report no active htlcs.
// Force Dave and Alice to reconnect before waiting for the htlcs to
// clear.
ctxt, _ = context.WithTimeout(ctxb, timeout)
err = net.EnsureConnected(ctxt, dave, net.Alice)
if err != nil {
t.Fatalf("unable to reconnect dave and carol: %v", err)
}
// After reconnection succeeds, the settles should be propagated all the
// way back to the sender. All nodes should report no active htlcs.
err = lntest.WaitPredicate(func() bool {
return assertNumActiveHtlcs(nodes, 0)
}, time.Second*15)
@ -7528,6 +7525,14 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
payReqs = []string{resp.PaymentRequest}
// Before completing the final payment request, ensure that the
// connection between Dave and Carol has been healed.
ctxt, _ = context.WithTimeout(ctxb, timeout)
err = net.EnsureConnected(ctxt, dave, carol)
if err != nil {
t.Fatalf("unable to reconnect dave and carol: %v", err)
}
// Using Carol as the source, pay to the 5 invoices from Bob created
// above.
ctxt, _ = context.WithTimeout(ctxb, timeout)