lntest: re-write AssertChannelExists to use WaitPredicate internally

Recent changes to the funding manger’s state machine have resulted in
some additional database calls during the funding process. This has
slowed down the tests by a few ms here and there. Recent integration
test runs have begun to fail due to AssertChannelExists returning an
error as the channel hasn’t fully propagated yet. In order to remedy
this, we’ll now use WaitPredicate to poll repeatedly to ensure. This
should serve to reduce flakes encountered within the integration tests.
This commit is contained in:
Olaoluwa Osuntokun 2017-12-21 11:35:23 +01:00
parent 72147fe1e5
commit c3f84b1a47
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -766,13 +766,31 @@ func (n *NetworkHarness) AssertChannelExists(ctx context.Context,
node *HarnessNode, chanPoint *wire.OutPoint) error {
req := &lnrpc.ListChannelsRequest{}
var predErr error
pred := func() bool {
resp, err := node.ListChannels(ctx, req)
if err != nil {
return fmt.Errorf("unable fetch node's channels: %v", err)
predErr = fmt.Errorf("unable fetch node's channels: %v", err)
return false
}
for _, channel := range resp.Channels {
if channel.ChannelPoint == chanPoint.String() {
return true
}
}
return false
}
if err := WaitPredicate(pred, time.Second*15); err != nil {
return fmt.Errorf("channel not found: %v", predErr)
}
return nil
}
// WaitPredicate is a helper test function that will wait for a timeout period
// of time until the passed predicate returns true. This function is helpful as
// timing doesn't always line up well when running integration tests with