routing: make sure StatusInitiated is notified when creating payments

This commit fixes `InitPayment` method to make sure the subscribers get
notified when new payments are created.
This commit is contained in:
yyforyongyu committed 2023-11-15 20:18:21 +08:00
1 parent 9e00799188
commit 9acbbf0ec7
2 files changed
+34 -21

No files matched your search

+14 -18
View File
@@ -196,7 +196,7 @@ func TestPaymentControlSubscribeAllSuccess(t *testing.T) {
err = pControl.InitPayment(info1.PaymentIdentifier, info1)
require.NoError(t, err)
// Subscription should succeed and immediately report the InFlight
// Subscription should succeed and immediately report the Initiated
// status.
subscription, err := pControl.SubscribeAllPayments()
require.NoError(t, err, "expected subscribe to succeed, but got: %v")
@@ -246,8 +246,8 @@ func TestPaymentControlSubscribeAllSuccess(t *testing.T) {
// for each payment.
results := make(map[lntypes.Hash]*channeldb.MPPayment)
// After exactly 5 updates both payments will/should have completed.
for i := 0; i < 5; i++ {
// After exactly 6 updates both payments will/should have completed.
for i := 0; i < 6; i++ {
select {
case item := <-subscription.Updates():
id := item.(*channeldb.MPPayment).Info.PaymentIdentifier
@@ -354,10 +354,6 @@ func TestPaymentControlUnsubscribeSuccess(t *testing.T) {
err = pControl.InitPayment(info.PaymentIdentifier, info)
require.NoError(t, err)
// Register a payment update.
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
require.NoError(t, err)
// Assert all subscriptions receive the update.
select {
case update1 := <-subscription1.Updates():
@@ -376,14 +372,9 @@ func TestPaymentControlUnsubscribeSuccess(t *testing.T) {
// Close the first subscription.
subscription1.Close()
// Register another update.
failInfo := channeldb.HTLCFailInfo{
Reason: channeldb.HTLCFailInternal,
}
_, err = pControl.FailAttempt(
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
)
require.NoError(t, err, "unable to fail htlc")
// Register a payment update.
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
require.NoError(t, err)
// Assert only subscription 2 receives the update.
select {
@@ -398,9 +389,14 @@ func TestPaymentControlUnsubscribeSuccess(t *testing.T) {
// Close the second subscription.
subscription2.Close()
// Register a last update.
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
require.NoError(t, err)
// Register another update.
failInfo := channeldb.HTLCFailInfo{
Reason: channeldb.HTLCFailInternal,
}
_, err = pControl.FailAttempt(
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
)
require.NoError(t, err, "unable to fail htlc")
// Assert no subscriptions receive the update.
require.Len(t, subscription1.Updates(), 0)