mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
Merge pull request #8135 from yyforyongyu/fix-flakes
multi: fix test flakes in unit tests and itests
This commit is contained in:
commit
7f652ee729
@ -3,6 +3,7 @@ package invoices_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/quick"
|
"testing/quick"
|
||||||
@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
invpkg "github.com/lightningnetwork/lnd/invoices"
|
invpkg "github.com/lightningnetwork/lnd/invoices"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
@ -1059,9 +1061,7 @@ func TestInvoiceExpiryWithRegistry(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := registry.Start(); err != nil {
|
require.NoError(t, registry.Start(), "cannot start registry")
|
||||||
t.Fatalf("cannot start registry: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now generate pending and invoices and add them to the registry while
|
// Now generate pending and invoices and add them to the registry while
|
||||||
// it is up and running. We'll manipulate the clock to let them expire.
|
// it is up and running. We'll manipulate the clock to let them expire.
|
||||||
@ -1085,10 +1085,8 @@ func TestInvoiceExpiryWithRegistry(t *testing.T) {
|
|||||||
ctxb, invoicesThatWillCancel[i],
|
ctxb, invoicesThatWillCancel[i],
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "cannot find invoice")
|
require.NoError(t, err, "cannot find invoice")
|
||||||
|
require.NotEqual(t, invpkg.ContractCanceled, invoice.State,
|
||||||
if invoice.State == invpkg.ContractCanceled {
|
"expected pending invoice, got canceled")
|
||||||
t.Fatalf("expected pending invoice, got canceled")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fwd time 1 day.
|
// Fwd time 1 day.
|
||||||
@ -1101,24 +1099,28 @@ func TestInvoiceExpiryWithRegistry(t *testing.T) {
|
|||||||
|
|
||||||
// canceled returns a bool to indicate whether all the invoices are
|
// canceled returns a bool to indicate whether all the invoices are
|
||||||
// canceled.
|
// canceled.
|
||||||
canceled := func() bool {
|
canceled := func() error {
|
||||||
for i := range expectedCancellations {
|
for i := range expectedCancellations {
|
||||||
invoice, err := registry.LookupInvoice(
|
invoice, err := registry.LookupInvoice(
|
||||||
ctxb, expectedCancellations[i],
|
ctxb, expectedCancellations[i],
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if invoice.State != invpkg.ContractCanceled {
|
if invoice.State != invpkg.ContractCanceled {
|
||||||
return false
|
return fmt.Errorf("expected state %v, got %v",
|
||||||
|
invpkg.ContractCanceled, invoice.State)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrospectively check that all invoices that were expected to be
|
// Retrospectively check that all invoices that were expected to be
|
||||||
// canceled are indeed canceled.
|
// canceled are indeed canceled.
|
||||||
require.Eventually(t, canceled, testTimeout, 10*time.Millisecond)
|
err = wait.NoError(canceled, testTimeout)
|
||||||
|
require.NoError(t, err, "timeout checking invoice state")
|
||||||
|
|
||||||
// Finally stop the registry.
|
// Finally stop the registry.
|
||||||
require.NoError(t, registry.Stop(), "failed to stop invoice registry")
|
require.NoError(t, registry.Stop(), "failed to stop invoice registry")
|
||||||
|
@ -2166,7 +2166,6 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
|
|||||||
if ht.IsNeutrinoBackend() {
|
if ht.IsNeutrinoBackend() {
|
||||||
// Mine a block to confirm Carol's 2nd level success tx.
|
// Mine a block to confirm Carol's 2nd level success tx.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
numTxesMempool--
|
|
||||||
numBlocks--
|
numBlocks--
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2195,12 +2194,6 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
|
|||||||
// anchor sweep tx in the mempool.
|
// anchor sweep tx in the mempool.
|
||||||
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
|
||||||
numTxesMempool++
|
numTxesMempool++
|
||||||
|
|
||||||
// For neutrino backend, because of the additional block mined,
|
|
||||||
// Bob's output is now mature.
|
|
||||||
if ht.IsNeutrinoBackend() {
|
|
||||||
numTxesMempool++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mine a block to clean the mempool.
|
// Mine a block to clean the mempool.
|
||||||
|
@ -1504,11 +1504,13 @@ func (h *HarnessTest) CleanupForceClose(hn *node.HarnessNode) {
|
|||||||
h.AssertNumPendingForceClose(hn, 1)
|
h.AssertNumPendingForceClose(hn, 1)
|
||||||
|
|
||||||
// Mine enough blocks for the node to sweep its funds from the force
|
// Mine enough blocks for the node to sweep its funds from the force
|
||||||
// closed channel.
|
// closed channel. The commit sweep resolver is able to broadcast the
|
||||||
|
// sweep tx up to one block before the CSV elapses, so wait until
|
||||||
|
// defaulCSV-1.
|
||||||
//
|
//
|
||||||
// The commit sweep resolver is able to broadcast the sweep tx up to
|
// NOTE: we might empty blocks here as we don't know the exact number
|
||||||
// one block before the CSV elapses, so wait until defaulCSV-1.
|
// of blocks to mine. This may end up mining more blocks than needed.
|
||||||
h.MineBlocks(node.DefaultCSV - 1)
|
h.MineEmptyBlocks(node.DefaultCSV - 1)
|
||||||
|
|
||||||
// The node should now sweep the funds, clean up by mining the sweeping
|
// The node should now sweep the funds, clean up by mining the sweeping
|
||||||
// tx.
|
// tx.
|
||||||
|
Loading…
Reference in New Issue
Block a user