lntest: re-write loop in ConnectNodes to use WaitPredicate

This commit is contained in:
Olaoluwa Osuntokun 2017-12-21 11:44:15 +01:00
parent 6992822865
commit b56dcc988b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -286,28 +286,28 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, a, b *HarnessNode) er
return err return err
} }
timeout := time.After(time.Second * 15) err = WaitPredicate(func() bool {
for {
select {
case <-timeout:
return fmt.Errorf("peers not connected within 15 seconds")
default:
}
// If node B is seen in the ListPeers response from node A, // If node B is seen in the ListPeers response from node A,
// then we can exit early as the connection has been fully // then we can exit early as the connection has been fully
// established. // established.
resp, err := a.ListPeers(ctx, &lnrpc.ListPeersRequest{}) resp, err := a.ListPeers(ctx, &lnrpc.ListPeersRequest{})
if err != nil { if err != nil {
return err return false
} }
for _, peer := range resp.Peers { for _, peer := range resp.Peers {
if peer.PubKey == b.PubKeyStr { if peer.PubKey == b.PubKeyStr {
return nil return true
} }
} }
return false
}, time.Second*15)
if err != nil {
return fmt.Errorf("peers not connected within 15 seconds")
} }
return nil
} }
// DisconnectNodes disconnects node a from node b by sending RPC message // DisconnectNodes disconnects node a from node b by sending RPC message