Skip to content

Commit 2281ccb

Browse files
authored
fix: unstable self payments test (#1147)
1 parent 98426a4 commit 2281ccb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

transactions/self_payments_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,19 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToIsolatedApp(t *testing.T) {
393393
// check notifications
394394
assert.Equal(t, 2, len(mockEventConsumer.GetConsumedEvents()))
395395

396-
assert.Equal(t, "nwc_payment_sent", mockEventConsumer.GetConsumedEvents()[1].Event)
397-
settledTransaction := mockEventConsumer.GetConsumedEvents()[1].Properties.(*db.Transaction)
396+
// we can't guarantee which notification was processed first because events are published async
397+
// so swap them if they are back to front
398+
consumedEvents := mockEventConsumer.GetConsumedEvents()
399+
if consumedEvents[1].Event == "nwc_payment_received" {
400+
consumedEvents[0], consumedEvents[1] = consumedEvents[1], consumedEvents[0]
401+
}
402+
403+
assert.Equal(t, "nwc_payment_sent", consumedEvents[1].Event)
404+
settledTransaction := consumedEvents[1].Properties.(*db.Transaction)
398405
assert.Equal(t, transaction.ID, settledTransaction.ID)
399406

400-
assert.Equal(t, "nwc_payment_received", mockEventConsumer.GetConsumedEvents()[0].Event)
401-
receivedTransaction := mockEventConsumer.GetConsumedEvents()[0].Properties.(*db.Transaction)
407+
assert.Equal(t, "nwc_payment_received", consumedEvents[0].Event)
408+
receivedTransaction := consumedEvents[0].Properties.(*db.Transaction)
402409
assert.Equal(t, incomingTransaction.ID, receivedTransaction.ID)
403410
}
404411

0 commit comments

Comments
 (0)