Skip to content

Commit

Permalink
lnd_test: adds polling to assertNumConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
cfromknecht authored and Roasbeef committed Aug 10, 2017
1 parent efd9cf1 commit 56a628d
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,43 @@ func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
}

//assertNumConnections asserts number current connections between two peers
func assertNumConnections(ctxt context.Context, t *harnessTest,
alice, bob *lightningNode, expected int) {
aliceNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil {
t.Fatalf("unable to fetch alice's node (%v) list peers %v",
alice.nodeID, err)
}
bobNumPeers, err := bob.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil {
t.Fatalf("unable to fetch bob's node (%v) list peers %v",
bob.nodeID, err)
}
if len(aliceNumPeers.Peers) != expected {
t.Fatalf("number of peers connected to alice is incorrect: expected %v, got %v",
expected, len(aliceNumPeers.Peers))
}
if len(bobNumPeers.Peers) != expected {
t.Fatalf("number of peers connected to bob is incorrect: expected %v, got %v",
expected, len(bobNumPeers.Peers))
func assertNumConnections(
ctxt context.Context,
t *harnessTest,
alice, bob *lightningNode,
expected int) {

const nPolls = 10

tick := time.Tick(300 * time.Millisecond)
for i := nPolls - 1; i >= 0; i-- {
select {
case <-tick:
aNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil {
t.Fatalf("unable to fetch alice's node (%v) list peers %v",
alice.nodeID, err)
}
bNumPeers, err := bob.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil {
t.Fatalf("unable to fetch bob's node (%v) list peers %v",
bob.nodeID, err)
}
if len(aNumPeers.Peers) != expected {
if i > 0 {
continue
}
t.Fatalf("number of peers connected to alice is incorrect: "+
"expected %v, got %v", expected, len(aNumPeers.Peers))
}
if len(bNumPeers.Peers) != expected {
if i > 0 {
continue
}
t.Fatalf("number of peers connected to bob is incorrect: "+
"expected %v, got %v", expected, len(bNumPeers.Peers))
}
}
}
}

Expand Down

0 comments on commit 56a628d

Please sign in to comment.