discovery: replace waitPredicate with lntest version
This commit is contained in:
parent
b96da69476
commit
c72db902f0
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/lnpeer"
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,29 +60,6 @@ func assertMsgsSent(t *testing.T, msgChan chan lnwire.Message,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitPredicate is a helper test function that will wait for a timeout period
|
|
||||||
// of time until the passed predicate returns true.
|
|
||||||
func waitPredicate(t *testing.T, timeout time.Duration, pred func() bool) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
const pollInterval = 20 * time.Millisecond
|
|
||||||
exitTimer := time.After(timeout)
|
|
||||||
|
|
||||||
for {
|
|
||||||
<-time.After(pollInterval)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-exitTimer:
|
|
||||||
t.Fatalf("predicate not satisfied after timeout")
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
if pred() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestReliableSenderFlow ensures that the flow for sending messages reliably to
|
// TestReliableSenderFlow ensures that the flow for sending messages reliably to
|
||||||
// a peer while taking into account its connection lifecycle works as expected.
|
// a peer while taking into account its connection lifecycle works as expected.
|
||||||
func TestReliableSenderFlow(t *testing.T) {
|
func TestReliableSenderFlow(t *testing.T) {
|
||||||
@ -262,27 +240,23 @@ func TestReliableSenderStaleMessages(t *testing.T) {
|
|||||||
// message store since it is seen as stale and has been sent at least
|
// message store since it is seen as stale and has been sent at least
|
||||||
// once. Once the message is removed, the peerHandler should be torn
|
// once. Once the message is removed, the peerHandler should be torn
|
||||||
// down as there are no longer any pending messages within the store.
|
// down as there are no longer any pending messages within the store.
|
||||||
var predErr error
|
err := lntest.WaitNoError(func() error {
|
||||||
waitPredicate(t, time.Second, func() bool {
|
|
||||||
msgs, err := reliableSender.cfg.MessageStore.MessagesForPeer(
|
msgs, err := reliableSender.cfg.MessageStore.MessagesForPeer(
|
||||||
peerPubKey,
|
peerPubKey,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
predErr = fmt.Errorf("unable to retrieve messages for "+
|
return fmt.Errorf("unable to retrieve messages for "+
|
||||||
"peer: %v", err)
|
"peer: %v", err)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if len(msgs) != 0 {
|
if len(msgs) != 0 {
|
||||||
predErr = fmt.Errorf("expected to not find any "+
|
return fmt.Errorf("expected to not find any "+
|
||||||
"messages for peer, found %d", len(msgs))
|
"messages for peer, found %d", len(msgs))
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
predErr = nil
|
return nil
|
||||||
return true
|
}, time.Second)
|
||||||
})
|
if err != nil {
|
||||||
if predErr != nil {
|
t.Fatal(err)
|
||||||
t.Fatal(predErr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override IsMsgStale to no longer mark messages as stale.
|
// Override IsMsgStale to no longer mark messages as stale.
|
||||||
|
Loading…
Reference in New Issue
Block a user