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