mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
routing: add wait.NoError to TestBlockDifferenceFix assertion
This fixes a flake I've seen in the wild lately: ``` --- FAIL: TestBlockDifferenceFix (0.01s) router_test.go:4335: height should have been updated to 5, instead got 4 FAIL FAIL github.com/lightningnetwork/lnd/routing 3.865s FAIL ``` We wrap things in an assertion loop to ensure that timing quirks don't cause the test to fail sporadically.
This commit is contained in:
parent
6be472eb98
commit
650827aade
2 changed files with 15 additions and 5 deletions
|
@ -313,7 +313,7 @@ you.
|
|||
|
||||
* [Catches up on blocks in the
|
||||
router](https://github.com/lightningnetwork/lnd/pull/5315) in order to fix an
|
||||
"out of order" error that crops up.
|
||||
"out of order" error that [crops up](https://github.com/lightningnetwork/lnd/pull/5748).
|
||||
|
||||
* [Fix healthcheck might be running after the max number of attempts are
|
||||
reached](https://github.com/lightningnetwork/lnd/pull/5686).
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
lnmock "github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
|
@ -4274,6 +4275,7 @@ func TestBlockDifferenceFix(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
initialBlockHeight := uint32(0)
|
||||
|
||||
// Starting height here is set to 0, which is behind where we want to be.
|
||||
ctx, cleanup := createTestCtxSingleNode(t, initialBlockHeight)
|
||||
defer cleanup()
|
||||
|
@ -4330,9 +4332,17 @@ func TestBlockDifferenceFix(t *testing.T) {
|
|||
<-ctx.chainView.notifyBlockAck
|
||||
}
|
||||
|
||||
// Then router height should be updated to the latest block.
|
||||
if atomic.LoadUint32(&ctx.router.bestHeight) != newBlockHeight {
|
||||
t.Fatalf("height should have been updated to %v, instead got "+
|
||||
"%v", newBlockHeight, ctx.router.bestHeight)
|
||||
err := wait.NoError(func() error {
|
||||
// Then router height should be updated to the latest block.
|
||||
if atomic.LoadUint32(&ctx.router.bestHeight) != newBlockHeight {
|
||||
return fmt.Errorf("height should have been updated "+
|
||||
"to %v, instead got %v", newBlockHeight,
|
||||
ctx.router.bestHeight)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, testTimeout)
|
||||
if err != nil {
|
||||
t.Fatalf("block height wasn't updated: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue