From 650827aade5dd5bdfd62d3f40c0ff121975c0fef Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 16 Sep 2021 15:21:00 -0700 Subject: [PATCH] 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. --- docs/release-notes/release-notes-0.14.0.md | 2 +- routing/router_test.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index 1b21a0674..964772acd 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -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). diff --git a/routing/router_test.go b/routing/router_test.go index b4d49d6c1..2633bd5ab 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -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) } }