lntest: add new WaitPredicate helper function
This commit is contained in:
parent
2154ec130f
commit
72147fe1e5
@ -773,11 +773,24 @@ func (n *NetworkHarness) AssertChannelExists(ctx context.Context,
|
|||||||
|
|
||||||
for _, channel := range resp.Channels {
|
for _, channel := range resp.Channels {
|
||||||
if channel.ChannelPoint == chanPoint.String() {
|
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 nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("channel not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpLogs reads the current logs generated by the passed node, and returns
|
// DumpLogs reads the current logs generated by the passed node, and returns
|
||||||
|
Loading…
Reference in New Issue
Block a user