itest+lntest: fix flake in testListSweeps
We now make sure we assert the `ListSweeps` results in a wait closure.
This commit is contained in:
4 files changed
+76
-21
No files matched your search
+6
-1
@@ -2059,9 +2059,14 @@ func (h *HarnessTest) CalculateTxesFeeRate(txns []*wire.MsgTx) int64 {
|
||||
func (h *HarnessTest) AssertSweepFound(hn *node.HarnessNode,
|
||||
sweep string, verbose bool, startHeight int32) {
|
||||
|
||||
req := &walletrpc.ListSweepsRequest{
|
||||
Verbose: verbose,
|
||||
StartHeight: startHeight,
|
||||
}
|
||||
|
||||
err := wait.NoError(func() error {
|
||||
// List all sweeps that alice's node had broadcast.
|
||||
sweepResp := hn.RPC.ListSweeps(verbose, startHeight)
|
||||
sweepResp := hn.RPC.ListSweeps(req)
|
||||
|
||||
var found bool
|
||||
if verbose {
|
||||
|
||||
@@ -2817,6 +2817,54 @@ func (h *HarnessTest) AssertAtLeastNumPendingSweeps(hn *node.HarnessNode,
|
||||
return results
|
||||
}
|
||||
|
||||
// AssertNumSweeps asserts the number of sweeps for the given node.
|
||||
func (h *HarnessTest) AssertNumSweeps(hn *node.HarnessNode,
|
||||
req *walletrpc.ListSweepsRequest,
|
||||
n int) *walletrpc.ListSweepsResponse {
|
||||
|
||||
var result *walletrpc.ListSweepsResponse
|
||||
|
||||
// The ListSweeps call is wrapped in wait.NoError to handle potential
|
||||
// timing issues. Sweep transactions might not be immediately reflected
|
||||
// or processed by the node after an event (e.g., channel closure or
|
||||
// block mining) due to propagation or processing delays. This ensures
|
||||
// the system retries the call until the expected sweep is found,
|
||||
// preventing test flakes caused by race conditions.
|
||||
err := wait.NoError(func() error {
|
||||
resp := hn.RPC.ListSweeps(req)
|
||||
|
||||
var txIDs []string
|
||||
if req.Verbose {
|
||||
details := resp.GetTransactionDetails()
|
||||
if details != nil {
|
||||
for _, tx := range details.Transactions {
|
||||
txIDs = append(txIDs, tx.TxHash)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ids := resp.GetTransactionIds()
|
||||
if ids != nil {
|
||||
txIDs = ids.TransactionIds
|
||||
}
|
||||
}
|
||||
|
||||
num := len(txIDs)
|
||||
|
||||
// Exit early if the num matches.
|
||||
if num == n {
|
||||
result = resp
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("want %d, got %d, sweeps: %v, req: %v", n,
|
||||
num, txIDs, req)
|
||||
}, DefaultTimeout)
|
||||
|
||||
require.NoErrorf(h, err, "%s: check num of sweeps timeout", hn.Name())
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindSweepingTxns asserts the expected number of sweeping txns are found in
|
||||
// the txns specified and return them.
|
||||
func (h *HarnessTest) FindSweepingTxns(txns []*wire.MsgTx,
|
||||
|
||||
@@ -169,16 +169,12 @@ func (h *HarnessRPC) VerifyMessageWithAddr(
|
||||
}
|
||||
|
||||
// ListSweeps makes a ListSweeps RPC call to the node's WalletKit client.
|
||||
func (h *HarnessRPC) ListSweeps(verbose bool,
|
||||
startHeight int32) *walletrpc.ListSweepsResponse {
|
||||
func (h *HarnessRPC) ListSweeps(
|
||||
req *walletrpc.ListSweepsRequest) *walletrpc.ListSweepsResponse {
|
||||
|
||||
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
req := &walletrpc.ListSweepsRequest{
|
||||
Verbose: verbose,
|
||||
StartHeight: startHeight,
|
||||
}
|
||||
resp, err := h.WalletKit.ListSweeps(ctxt, req)
|
||||
h.NoError(err, "ListSweeps")
|
||||
|
||||
|
||||
Reference in new issue
Block a user