lntest: fix completePaymentRequestsAssertStatus

This commit moves the assertion `AssertPaymentStatusFromStream` outside
of the goroutine so the test won't fail after the case is finished.
This commit is contained in:
yyforyongyu 2022-11-02 03:39:24 +08:00
parent 178e4b0103
commit 7bd8ae08c0
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -1271,7 +1271,7 @@ func (h *HarnessTest) completePaymentRequestsAssertStatus(hn *node.HarnessNode,
paymentRequests []string, status lnrpc.Payment_PaymentStatus) {
// Create a buffered chan to signal the results.
results := make(chan struct{}, len(paymentRequests))
results := make(chan rpc.PaymentClient, len(paymentRequests))
// send sends a payment and asserts if it doesn't succeeded.
send := func(payReq string) {
@ -1281,10 +1281,9 @@ func (h *HarnessTest) completePaymentRequestsAssertStatus(hn *node.HarnessNode,
FeeLimitMsat: noFeeLimitMsat,
}
stream := hn.RPC.SendPayment(req)
h.AssertPaymentStatusFromStream(stream, status)
// Signal success.
results <- struct{}{}
// Signal sent succeeded.
results <- stream
}
// Launch all payments simultaneously.
@ -1293,16 +1292,12 @@ func (h *HarnessTest) completePaymentRequestsAssertStatus(hn *node.HarnessNode,
go send(payReqCopy)
}
// Wait for all payments to report success.
// Wait for all payments to report the expected status.
timer := time.After(DefaultTimeout)
count := 0
select {
case <-results:
count++
// Exit if the expected number of results are received.
if count == len(paymentRequests) {
return
}
case stream := <-results:
h.AssertPaymentStatusFromStream(stream, status)
case <-timer:
require.Fail(h, "timeout", "waiting payment results timeout")
}