Skip to content

Commit

Permalink
Merge pull request lightninglabs#795 from lightninglabs/load-test-sta…
Browse files Browse the repository at this point in the history
…bility

itest: use configurable timeout for load test
  • Loading branch information
Roasbeef authored Feb 12, 2024
2 parents a6415f8 + b6c327b commit ac8a237
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 13 additions & 2 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,19 @@ func AssertAddrEvent(t *testing.T, client taprpc.TaprootAssetsClient,
addr *taprpc.Addr, numEvents int,
expectedStatus taprpc.AddrEventStatus) {

AssertAddrEventCustomTimeout(
t, client, addr, numEvents, expectedStatus, defaultWaitTimeout,
)
}

// AssertAddrEventCustomTimeout makes sure the given address was detected by
// the given daemon within the given timeout.
func AssertAddrEventCustomTimeout(t *testing.T,
client taprpc.TaprootAssetsClient, addr *taprpc.Addr, numEvents int,
expectedStatus taprpc.AddrEventStatus, timeout time.Duration) {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
ctxt, cancel := context.WithTimeout(ctxb, timeout)
defer cancel()

err := wait.NoError(func() error {
Expand Down Expand Up @@ -717,7 +728,7 @@ func AssertAddrEvent(t *testing.T, client taprpc.TaprootAssetsClient,
t.Logf("Got address event %s", eventJSON)

return nil
}, defaultWaitTimeout)
}, timeout)
require.NoError(t, err)
}

Expand Down
15 changes: 10 additions & 5 deletions itest/loadtest/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
prand "math/rand"
"testing"
"time"

"github.com/btcsuite/btcd/rpcclient"
"github.com/lightninglabs/taproot-assets/itest"
Expand Down Expand Up @@ -44,7 +45,7 @@ func sendTest(t *testing.T, ctx context.Context, cfg *Config) {

sendAssets(
t, ctxt, cfg.NumAssets, cfg.SendType, send, receive,
bitcoinClient,
bitcoinClient, cfg.TestTimeout,
)

t.Logf("Finished %d of %d send operations", i, cfg.NumSends)
Expand All @@ -55,7 +56,7 @@ func sendTest(t *testing.T, ctx context.Context, cfg *Config) {
// node to the other node.
func sendAssets(t *testing.T, ctx context.Context, numAssets uint64,
assetType taprpc.AssetType, send, receive *rpcClient,
bitcoinClient *rpcclient.Client) {
bitcoinClient *rpcclient.Client, timeout time.Duration) {

// Query the asset we'll be sending, so we can assert some things about
// it later.
Expand Down Expand Up @@ -91,16 +92,20 @@ func sendAssets(t *testing.T, ctx context.Context, numAssets uint64,
require.Eventually(t, func() bool {
newTransfers := send.listTransfersSince(t, ctx, transfersBefore)
return len(newTransfers) == 1
}, defaultTimeout, wait.PollInterval)
}, timeout, wait.PollInterval)

// And for it to be detected on the receiving node.
itest.AssertAddrEvent(t, receive, addr, 1, statusDetected)
itest.AssertAddrEventCustomTimeout(
t, receive, addr, 1, statusDetected, timeout,
)

// Mine a block to confirm the transfer.
itest.MineBlocks(t, bitcoinClient, 1, 1)

// Now the transfer should go to completed eventually.
itest.AssertAddrEvent(t, receive, addr, 1, statusCompleted)
itest.AssertAddrEventCustomTimeout(
t, receive, addr, 1, statusCompleted, timeout,
)
}

// pickSendNode picks a node at random, checks whether it has enough assets of
Expand Down

0 comments on commit ac8a237

Please sign in to comment.