Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itest: fix async payment benchmark timeout flakes #5579

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/release-notes-0.14.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ addholdinvoice call](https://github.com/lightningnetwork/lnd/pull/5533).
* [Fixed typo in `dest_custom_records` description comment](https://github.com/lightningnetwork/lnd/pull/5541).
* [Bumped version of `github.com/miekg/dns` library to fix a Dependabot
alert](https://github.com/lightningnetwork/lnd/pull/5576).
* [Fixed timeout flakes in async payment benchmark tests](https://github.com/lightningnetwork/lnd/pull/5579).

## Database

Expand Down
94 changes: 57 additions & 37 deletions lntest/itest/lnd_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"reflect"
"time"

Expand All @@ -14,6 +15,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
)

func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
Expand Down Expand Up @@ -374,31 +376,40 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
}

return true
}, time.Second*5)
}, defaultTimeout)
if err != nil {
t.Fatalf("failed to assert alice's pending htlcs and/or remote/local balance")
}

// Wait for Bob to receive revocation from Alice.
time.Sleep(2 * time.Second)
err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
bobChan, err := getChanInfo(ctxt, net.Bob)
if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err)
guggero marked this conversation as resolved.
Show resolved Hide resolved
}

ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
bobChan, err := getChanInfo(ctxt, net.Bob)
if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err)
}
if len(bobChan.PendingHtlcs) != 0 {
t.Fatalf("bob's pending htlcs is incorrect, got %v, "+
"expected %v", len(bobChan.PendingHtlcs), 0)
}
if bobChan.LocalBalance != bobAmt {
t.Fatalf("bob's local balance is incorrect, got %v, expected"+
" %v", bobChan.LocalBalance, bobAmt)
}
if bobChan.RemoteBalance != aliceAmt {
t.Fatalf("bob's remote balance is incorrect, got %v, "+
"expected %v", bobChan.RemoteBalance, aliceAmt)
}
if len(bobChan.PendingHtlcs) != 0 {
return fmt.Errorf("bob's pending htlcs is incorrect, "+
"got %v, expected %v",
len(bobChan.PendingHtlcs), 0)
}

if bobChan.LocalBalance != bobAmt {
return fmt.Errorf("bob's local balance is incorrect, "+
"got %v, expected %v", bobChan.LocalBalance,
bobAmt)
}

if bobChan.RemoteBalance != aliceAmt {
return fmt.Errorf("bob's remote balance is incorrect, "+
"got %v, expected %v", bobChan.RemoteBalance,
aliceAmt)
}

return nil
}, defaultTimeout)
require.NoError(t.t, err)

t.Log("\tBenchmark info: Elapsed time: ", timeTaken)
t.Log("\tBenchmark info: TPS: ", float64(numInvoices)/timeTaken.Seconds())
Expand Down Expand Up @@ -539,25 +550,34 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)

// Wait for Alice and Bob to receive revocations messages, and update
// states, i.e. balance info.
time.Sleep(1 * time.Second)
err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
aliceInfo, err := getChanInfo(ctxt, net.Alice)
if err != nil {
t.Fatalf("unable to get alice's channel info: %v", err)
}

ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
aliceInfo, err := getChanInfo(ctxt, net.Alice)
if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err)
}
if aliceInfo.RemoteBalance != bobAmt {
t.Fatalf("alice's remote balance is incorrect, got %v, "+
"expected %v", aliceInfo.RemoteBalance, bobAmt)
}
if aliceInfo.LocalBalance != aliceAmt {
t.Fatalf("alice's local balance is incorrect, got %v, "+
"expected %v", aliceInfo.LocalBalance, aliceAmt)
}
if len(aliceInfo.PendingHtlcs) != 0 {
t.Fatalf("alice's pending htlcs is incorrect, got %v, "+
"expected %v", len(aliceInfo.PendingHtlcs), 0)
}
if aliceInfo.RemoteBalance != bobAmt {
return fmt.Errorf("alice's remote balance is incorrect, "+
"got %v, expected %v", aliceInfo.RemoteBalance,
bobAmt)
}

if aliceInfo.LocalBalance != aliceAmt {
return fmt.Errorf("alice's local balance is incorrect, "+
"got %v, expected %v", aliceInfo.LocalBalance,
aliceAmt)
}

if len(aliceInfo.PendingHtlcs) != 0 {
return fmt.Errorf("alice's pending htlcs is incorrect, "+
"got %v expected %v",
len(aliceInfo.PendingHtlcs), 0)
}

return nil
}, defaultTimeout)
require.NoError(t.t, err)

// Next query for Bob's and Alice's channel states, in order to confirm
// that all payment have been successful transmitted.
Expand Down