test: modify assertNumConnections to use a stoppable ticker

This commit is contained in:
Olaoluwa Osuntokun 2017-11-02 15:45:13 -07:00
parent b3000b621b
commit 34a165dd12
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -266,19 +266,18 @@ 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( func assertNumConnections(ctxt context.Context, t *harnessTest,
ctxt context.Context, alice, bob *lightningNode, expected int) {
t *harnessTest,
alice, bob *lightningNode,
expected int) {
const nPolls = 10 const nPolls = 10
tick := time.Tick(300 * time.Millisecond) tick := time.NewTicker(300 * time.Millisecond)
defer tick.Stop()
for i := nPolls - 1; i >= 0; i-- { for i := nPolls - 1; i >= 0; i-- {
select { select {
case <-tick: case <-tick.C:
aNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{}) aNumPeers, err := alice.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil { if err != nil {
t.Fatalf("unable to fetch alice's node (%v) list peers %v", t.Fatalf("unable to fetch alice's node (%v) list peers %v",