lntest: add new WaitPredicate helper function

This commit is contained in:
Olaoluwa Osuntokun 2017-12-21 11:33:28 +01:00
parent 2154ec130f
commit 72147fe1e5
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 15 additions and 2 deletions

View File

@ -773,11 +773,24 @@ func (n *NetworkHarness) AssertChannelExists(ctx context.Context,
for _, channel := range resp.Channels {
if channel.ChannelPoint == chanPoint.String() {
// 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
// several running lnd nodes. This function gives callers a way to assert that
// some property is upheld within a particular time frame.
func WaitPredicate(pred func() bool, timeout time.Duration) error {
exitTimer := time.After(timeout)
for {
select {
case <-exitTimer:
return fmt.Errorf("predicate not satisfied after time out")
default:
}
if pred() {
return nil
}
}
return fmt.Errorf("channel not found")
}
// DumpLogs reads the current logs generated by the passed node, and returns