Skip to content

Commit

Permalink
test: fix basic funding integration test flakiness
Browse files Browse the repository at this point in the history
This commit fixes some flakiness exhibited in the current basic funding
workflow tests. This test can fail occasionally in resource constrained
environment due to a race condition which arises after Alice learns of
the channel, but Bob is still waiting for Alice’s notification. As a
temporary fix, we now only check Alice’s state for the existence of the
channel.
  • Loading branch information
Roasbeef committed Sep 6, 2016
1 parent 803b66f commit d764493
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
7 changes: 5 additions & 2 deletions lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func testBasicChannelFunding(net *networkHarness, t *testing.T) {

// The channel should be listed in the peer information returned by
// both peers.
err = net.AssertChannelExists(ctxb, net.AliceClient, net.BobClient,
fundingChanPoint)
chanPoint := wire.OutPoint{
Hash: *fundingTxID,
Index: fundingChanPoint.OutputIndex,
}
err = net.AssertChannelExists(ctxb, net.AliceClient, &chanPoint)
if err != nil {
t.Fatalf("unable to assert channel existence: %v", err)
}
Expand Down
46 changes: 11 additions & 35 deletions networktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -585,48 +584,25 @@ func (n *networkHarness) WaitForChannelClose(closeChanStream lnrpc.Lightning_Clo
}

// AssertChannelExists asserts that an active channel identified by
// channelPoint exists between nodeA and nodeB.
func (n *networkHarness) AssertChannelExists(ctx context.Context, nodeA, nodeB lnrpc.LightningClient,
channelPoint *lnrpc.ChannelPoint) error {
// channelPoint is known to exist from the point-of-view of node..
func (n *networkHarness) AssertChannelExists(ctx context.Context,
node lnrpc.LightningClient, chanPoint *wire.OutPoint) error {

// TODO(roasbeef): remove and use "listchannels" command after
// implemented. Also make logic below more generic after addition of
// the RPC.
req := &lnrpc.ListPeersRequest{}
alicePeerInfo, err := nodeA.ListPeers(ctx, req)
peerInfo, err := node.ListPeers(ctx, req)
if err != nil {
return fmt.Errorf("unable to list nodeA peers: %v", err)
}
bobPeerInfo, err := nodeB.ListPeers(ctx, req)
if err != nil {
return fmt.Errorf("unable to list nodeB peers: %v", err)
}
aliceChannels := alicePeerInfo.Peers[0].Channels
if len(aliceChannels) < 1 {
return fmt.Errorf("alice should have an active channel, instead have %v",
len(aliceChannels))
}
bobChannels := bobPeerInfo.Peers[0].Channels
if len(bobChannels) < 1 {
return fmt.Errorf("bob should have an active channel, instead have %v",
len(bobChannels))
}

txid, err := wire.NewShaHash(channelPoint.FundingTxid)
if err != nil {
return err
}

aliceTxID := alicePeerInfo.Peers[0].Channels[0].ChannelPoint
bobTxID := bobPeerInfo.Peers[0].Channels[0].ChannelPoint
if !strings.Contains(bobTxID, txid.String()) {
return fmt.Errorf("alice's channel not found")
}
if !strings.Contains(aliceTxID, txid.String()) {
return fmt.Errorf("bob's channel not found")
for _, peer := range peerInfo.Peers {
for _, channel := range peer.Channels {
if channel.ChannelPoint == chanPoint.String() {
return nil
}
}
}

return nil
return fmt.Errorf("channel not found")
}

// initRpcClient attempts to make an rpc connection, then create a gRPC client
Expand Down

0 comments on commit d764493

Please sign in to comment.