From 2c3641e91520cb30896f2d7a501901ab50f5c5c5 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 7 Apr 2020 11:53:15 -0700 Subject: [PATCH] htlcswitch/link_test: fix preimage assertion This flakes locally for me on darwin. --- htlcswitch/link_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 965ecdb2e..3f86bbfe7 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -30,6 +30,7 @@ import ( "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnpeer" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -4661,15 +4662,24 @@ func checkHasPreimages(t *testing.T, coreLink *channelLink, t.Helper() - for i := range htlcs { - _, ok := coreLink.cfg.PreimageCache.LookupPreimage( - htlcs[i].PaymentHash, - ) - if ok != expOk { - t.Fatalf("expected to find witness: %v, "+ + err := wait.NoError(func() error { + for i := range htlcs { + _, ok := coreLink.cfg.PreimageCache.LookupPreimage( + htlcs[i].PaymentHash, + ) + if ok == expOk { + continue + } + + return fmt.Errorf("expected to find witness: %v, "+ "got %v for hash=%x", expOk, ok, htlcs[i].PaymentHash) } + + return nil + }, 5*time.Second) + if err != nil { + t.Fatalf("unable to find preimages: %v", err) } }