Merge pull request #5579 from bhandras/payment_bench_timeout_flake

itest: fix async payment benchmark timeout flakes
This commit is contained in:
Oliver Gugger 2021-07-27 16:10:41 +02:00 committed by GitHub
commit 046d4513b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 37 deletions

View File

@ -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). * [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 * [Bumped version of `github.com/miekg/dns` library to fix a Dependabot
alert](https://github.com/lightningnetwork/lnd/pull/5576). alert](https://github.com/lightningnetwork/lnd/pull/5576).
* [Fixed timeout flakes in async payment benchmark tests](https://github.com/lightningnetwork/lnd/pull/5579).
## Database ## Database

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"fmt"
"reflect" "reflect"
"time" "time"
@ -14,6 +15,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
) )
func testListPayments(net *lntest.NetworkHarness, t *harnessTest) { func testListPayments(net *lntest.NetworkHarness, t *harnessTest) {
@ -374,32 +376,41 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
} }
return true return true
}, time.Second*5) }, defaultTimeout)
if err != nil { if err != nil {
t.Fatalf("failed to assert alice's pending htlcs and/or remote/local balance") t.Fatalf("failed to assert alice's pending htlcs and/or remote/local balance")
} }
// Wait for Bob to receive revocation from Alice. // Wait for Bob to receive revocation from Alice.
time.Sleep(2 * time.Second) err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
bobChan, err := getChanInfo(ctxt, net.Bob) bobChan, err := getChanInfo(ctxt, net.Bob)
if err != nil { if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err) t.Fatalf("unable to get bob's channel info: %v", err)
} }
if len(bobChan.PendingHtlcs) != 0 { if len(bobChan.PendingHtlcs) != 0 {
t.Fatalf("bob's pending htlcs is incorrect, got %v, "+ return fmt.Errorf("bob's pending htlcs is incorrect, "+
"expected %v", len(bobChan.PendingHtlcs), 0) "got %v, expected %v",
len(bobChan.PendingHtlcs), 0)
} }
if bobChan.LocalBalance != bobAmt { if bobChan.LocalBalance != bobAmt {
t.Fatalf("bob's local balance is incorrect, got %v, expected"+ return fmt.Errorf("bob's local balance is incorrect, "+
" %v", bobChan.LocalBalance, bobAmt) "got %v, expected %v", bobChan.LocalBalance,
bobAmt)
} }
if bobChan.RemoteBalance != aliceAmt { if bobChan.RemoteBalance != aliceAmt {
t.Fatalf("bob's remote balance is incorrect, got %v, "+ return fmt.Errorf("bob's remote balance is incorrect, "+
"expected %v", bobChan.RemoteBalance, aliceAmt) "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: Elapsed time: ", timeTaken)
t.Log("\tBenchmark info: TPS: ", float64(numInvoices)/timeTaken.Seconds()) t.Log("\tBenchmark info: TPS: ", float64(numInvoices)/timeTaken.Seconds())
@ -539,26 +550,35 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
// Wait for Alice and Bob to receive revocations messages, and update // Wait for Alice and Bob to receive revocations messages, and update
// states, i.e. balance info. // states, i.e. balance info.
time.Sleep(1 * time.Second) err = wait.NoError(func() error {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
aliceInfo, err := getChanInfo(ctxt, net.Alice) aliceInfo, err := getChanInfo(ctxt, net.Alice)
if err != nil { if err != nil {
t.Fatalf("unable to get bob's channel info: %v", err) t.Fatalf("unable to get alice's channel info: %v", err)
} }
if aliceInfo.RemoteBalance != bobAmt { if aliceInfo.RemoteBalance != bobAmt {
t.Fatalf("alice's remote balance is incorrect, got %v, "+ return fmt.Errorf("alice's remote balance is incorrect, "+
"expected %v", aliceInfo.RemoteBalance, bobAmt) "got %v, expected %v", aliceInfo.RemoteBalance,
bobAmt)
} }
if aliceInfo.LocalBalance != aliceAmt { if aliceInfo.LocalBalance != aliceAmt {
t.Fatalf("alice's local balance is incorrect, got %v, "+ return fmt.Errorf("alice's local balance is incorrect, "+
"expected %v", aliceInfo.LocalBalance, aliceAmt) "got %v, expected %v", aliceInfo.LocalBalance,
aliceAmt)
} }
if len(aliceInfo.PendingHtlcs) != 0 { if len(aliceInfo.PendingHtlcs) != 0 {
t.Fatalf("alice's pending htlcs is incorrect, got %v, "+ return fmt.Errorf("alice's pending htlcs is incorrect, "+
"expected %v", len(aliceInfo.PendingHtlcs), 0) "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 // Next query for Bob's and Alice's channel states, in order to confirm
// that all payment have been successful transmitted. // that all payment have been successful transmitted.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)