lntest+wait: replace sleeps in assertAmountSent

This commit constructs a helper closure assertAmountSent that can be
reused by other functions. The closure returns an error so that it can
be used with wait.NoError or the new wait.InvariantNoError. The latter
is added since the predicate could otherwise pass immediately for the
sphinx_replay_persistence tests, but change shortly after. It also
rounds out the wait package so that we offer all combinations of
predicate and no-error style waits.
This commit is contained in:
Conner Fromknecht committed 2019-12-18 23:57:12 -08:00
1 parent f868bc128b
commit 396a978cec
2 files changed
+88 -61

No files matched your search

+20
View File
@@ -76,3 +76,23 @@ func Invariant(statement func() bool, timeout time.Duration) error {
}
}
}
// InvariantNoError is a wrapper around Invariant that waits out the duration
// specified by timeout. It fails if the predicate ever returns an error during
// that time.
func InvariantNoError(f func() error, timeout time.Duration) error {
var predErr error
pred := func() bool {
if err := f(); err != nil {
predErr = err
return false
}
return true
}
if err := Invariant(pred, timeout); err != nil {
return predErr
}
return nil
}