Merge pull request #5905 from guggero/itest-fixes

itest: fix two flakes
This commit is contained in:
Olaoluwa Osuntokun 2021-11-02 14:59:37 -07:00 committed by GitHub
commit b99157efbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View File

@ -462,6 +462,9 @@ messages directly. There is no routing/path finding involved.
* [Run channeldb tests on postgres](https://github.com/lightningnetwork/lnd/pull/5550) * [Run channeldb tests on postgres](https://github.com/lightningnetwork/lnd/pull/5550)
* [Fixed two flakes in itests that were caused by things progressing too
fast](https://github.com/lightningnetwork/lnd/pull/5905).
## Database ## Database
* [Ensure single writer for legacy * [Ensure single writer for legacy

View File

@ -1615,7 +1615,9 @@ func (n *NetworkHarness) sendCoins(amt btcutil.Amount, target *HarnessNode,
return err return err
} }
expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt fullInitialBalance := initialBalance.ConfirmedBalance +
initialBalance.UnconfirmedBalance
expectedBalance := btcutil.Amount(fullInitialBalance) + amt
return target.WaitForBalance(expectedBalance, true) return target.WaitForBalance(expectedBalance, true)
} }

View File

@ -209,8 +209,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
// Alice opens a smaller channel. This works since it will have a // Alice opens a smaller channel. This works since it will have a
// change output. // change output.
aliceChanPoint1 := openChannelAndAssert( aliceChanPoint1 := openChannelAndAssert(
t, net, alice, bob, t, net, alice, bob, lntest.OpenChannelParams{
lntest.OpenChannelParams{
Amt: chanAmt / 4, Amt: chanAmt / 4,
}, },
) )
@ -326,7 +325,7 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
block = mineBlocks(t, net, 1, 1)[0] block = mineBlocks(t, net, 1, 1)[0]
// The sweep transaction should have exactly one inputs as we only had // The sweep transaction should have exactly one inputs as we only had
// the the single output from above in the wallet. // the single output from above in the wallet.
sweepTx = block.Transactions[1] sweepTx = block.Transactions[1]
if len(sweepTx.TxIn) != 1 { if len(sweepTx.TxIn) != 1 {
t.Fatalf("expected 1 inputs instead have %v", len(sweepTx.TxIn)) t.Fatalf("expected 1 inputs instead have %v", len(sweepTx.TxIn))
@ -352,9 +351,12 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("Alice's balance did not increase after channel close") t.Fatalf("Alice's balance did not increase after channel close")
} }
// Assert there are no open or pending channels anymore.
assertNumPendingChannels(t, alice, 0, 0)
assertNodeNumChannels(t, alice, 0)
// We'll wait for the balance to reflect that the channel has been // We'll wait for the balance to reflect that the channel has been
// closed and the funds are in the wallet. // closed and the funds are in the wallet.
sweepReq = &lnrpc.SendCoinsRequest{ sweepReq = &lnrpc.SendCoinsRequest{
Addr: minerAddr.String(), Addr: minerAddr.String(),
SendAll: true, SendAll: true,

View File

@ -638,6 +638,16 @@ func wsTestPingPongTimeout(ht *harnessTest, net *lntest.NetworkHarness) {
} }
}() }()
// The SubscribeInvoices call returns immediately after the gRPC/REST
// connection is established. But it can happen that the goroutine in
// lnd that actually registers the subscriber in the invoice backend
// didn't get any CPU time just yet. So we can run into the situation
// where we add our first invoice _before_ the subscription client is
// registered. If that happens, we'll never get notified about the
// invoice in question. So all we really can do is wait a bit here to
// make sure the subscription is registered correctly.
time.Sleep(500 * time.Millisecond)
// Let's create five invoices and wait for them to arrive. We'll wait // Let's create five invoices and wait for them to arrive. We'll wait
// for at least one ping/pong cycle between each invoice. // for at least one ping/pong cycle between each invoice.
ctxb := context.Background() ctxb := context.Background()