htlcswitch/link_test: use require.Eventually

Intead of sleeping we use require.Eventually in two cases the flake was
flaky.
This commit is contained in:
Johan T. Halseth 2020-12-04 10:49:09 +01:00
parent daf7c8a854
commit 548827fe89
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -35,6 +35,7 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/ticker" "github.com/lightningnetwork/lnd/ticker"
"github.com/stretchr/testify/require"
) )
const ( const (
@ -1148,27 +1149,25 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) {
) )
// Wait for Alice to receive the revocation. // Wait for Alice to receive the revocation.
time.Sleep(100 * time.Millisecond) require.Eventually(t, func() bool {
if n.aliceChannelLink.Bandwidth() != aliceBandwidthBefore {
return false
}
if n.aliceChannelLink.Bandwidth() != aliceBandwidthBefore { if n.firstBobChannelLink.Bandwidth() != firstBobBandwidthBefore {
t.Fatal("the bandwidth of alice channel link which handles " + return false
"alice->bob channel should be the same") }
}
if n.firstBobChannelLink.Bandwidth() != firstBobBandwidthBefore { if n.secondBobChannelLink.Bandwidth() != secondBobBandwidthBefore {
t.Fatal("the bandwidth of bob channel link which handles " + return false
"alice->bob channel should be the same") }
}
if n.secondBobChannelLink.Bandwidth() != secondBobBandwidthBefore { if n.carolChannelLink.Bandwidth() != carolBandwidthBefore {
t.Fatal("the bandwidth of bob channel link which handles " + return false
"bob->carol channel should be the same") }
}
if n.carolChannelLink.Bandwidth() != carolBandwidthBefore { return true
t.Fatal("the bandwidth of carol channel link which handles " + }, 10*time.Second, 100*time.Millisecond)
"bob->carol channel should be the same")
}
} }
// TestChannelLinkMultiHopUnknownNextHop construct the chain of hops // TestChannelLinkMultiHopUnknownNextHop construct the chain of hops
@ -3779,32 +3778,29 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
t.Fatalf("alice didn't query for the new network fee") t.Fatalf("alice didn't query for the new network fee")
} }
// Give the links some time to process the fee update.
time.Sleep(time.Second)
// Record the fee rates after the links have processed the fee // Record the fee rates after the links have processed the fee
// update and ensure they are correct based on whether a fee // update and ensure they are correct based on whether a fee
// update should have been triggered. // update should have been triggered.
aliceAfter := channels.aliceToBob.CommitFeeRate() require.Eventually(t, func() bool {
bobAfter := channels.bobToAlice.CommitFeeRate() aliceAfter := channels.aliceToBob.CommitFeeRate()
bobAfter := channels.bobToAlice.CommitFeeRate()
switch { switch {
case shouldUpdate && aliceAfter != newFeeRate: case shouldUpdate && aliceAfter != newFeeRate:
t.Fatalf("alice's fee rate didn't change: expected %v, "+ return false
"got %v", newFeeRate, aliceAfter)
case shouldUpdate && bobAfter != newFeeRate: case shouldUpdate && bobAfter != newFeeRate:
t.Fatalf("bob's fee rate didn't change: expected %v, "+ return false
"got %v", newFeeRate, bobAfter)
case !shouldUpdate && aliceAfter != aliceBefore: case !shouldUpdate && aliceAfter != aliceBefore:
t.Fatalf("alice's fee rate shouldn't have changed: "+ return false
"expected %v, got %v", aliceAfter, aliceAfter)
case !shouldUpdate && bobAfter != bobBefore: case !shouldUpdate && bobAfter != bobBefore:
t.Fatalf("bob's fee rate shouldn't have changed: "+ return false
"expected %v, got %v", bobBefore, bobAfter) }
}
return true
}, 10*time.Second, time.Second)
} }
// Triggering the link to update the fee of the channel with the same // Triggering the link to update the fee of the channel with the same