lnd_test: adds polling to assertNumConnections
This commit is contained in:
parent
efd9cf12b8
commit
56a628d3ad
56
lnd_test.go
56
lnd_test.go
@ -267,25 +267,43 @@ func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//assertNumConnections asserts number current connections between two peers
|
//assertNumConnections asserts number current connections between two peers
|
||||||
func assertNumConnections(ctxt context.Context, t *harnessTest,
|
func assertNumConnections(
|
||||||
alice, bob *lightningNode, expected int) {
|
ctxt context.Context,
|
||||||
aliceNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
|
t *harnessTest,
|
||||||
if err != nil {
|
alice, bob *lightningNode,
|
||||||
t.Fatalf("unable to fetch alice's node (%v) list peers %v",
|
expected int) {
|
||||||
alice.nodeID, err)
|
|
||||||
}
|
const nPolls = 10
|
||||||
bobNumPeers, err := bob.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
|
|
||||||
if err != nil {
|
tick := time.Tick(300 * time.Millisecond)
|
||||||
t.Fatalf("unable to fetch bob's node (%v) list peers %v",
|
for i := nPolls - 1; i >= 0; i-- {
|
||||||
bob.nodeID, err)
|
select {
|
||||||
}
|
case <-tick:
|
||||||
if len(aliceNumPeers.Peers) != expected {
|
aNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
|
||||||
t.Fatalf("number of peers connected to alice is incorrect: expected %v, got %v",
|
if err != nil {
|
||||||
expected, len(aliceNumPeers.Peers))
|
t.Fatalf("unable to fetch alice's node (%v) list peers %v",
|
||||||
}
|
alice.nodeID, err)
|
||||||
if len(bobNumPeers.Peers) != expected {
|
}
|
||||||
t.Fatalf("number of peers connected to bob is incorrect: expected %v, got %v",
|
bNumPeers, err := bob.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
|
||||||
expected, len(bobNumPeers.Peers))
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user