Merge pull request #7336 from positiveblue/fix-race-condition

routing: fix reace condition in `TestUpdatePaymentState`
This commit is contained in:
Oliver Gugger 2023-01-18 09:26:28 +01:00 committed by GitHub
commit 716febc6c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 36 deletions

View file

@ -219,6 +219,9 @@ data.
* [Fix gomnd linter error](https://github.com/lightningnetwork/lnd/pull/7325)
* [Fix race condition in
`TestUpdatePaymentState`](https://github.com/lightningnetwork/lnd/pull/7336)
## `lncli`
* [Add an `insecure` flag to skip tls auth as well as a `metadata` string slice

View file

@ -938,40 +938,14 @@ func TestUpdatePaymentState(t *testing.T) {
// paymentHash is the identifier on paymentLifecycle.
paymentHash := lntypes.Hash{}
preimage := lntypes.Preimage{}
failureReasonError := channeldb.FailureReasonError
// TODO(yy): make MPPayment into an interface so we can mock it. The
// current design implicitly tests the methods SendAmt, TerminalInfo,
// and InFlightHTLCs on channeldb.MPPayment, which is not good. Once
// MPPayment becomes an interface, we can then mock these methods here.
// SentAmt returns 90, 10
// TerminalInfo returns non-nil, nil
// InFlightHTLCs returns 0
var preimage lntypes.Preimage
paymentSettled := &channeldb.MPPayment{
HTLCs: []channeldb.HTLCAttempt{
makeSettledAttempt(100, 10, preimage),
},
}
// SentAmt returns 0, 0
// TerminalInfo returns nil, non-nil
// InFlightHTLCs returns 0
reason := channeldb.FailureReasonError
paymentFailed := &channeldb.MPPayment{
FailureReason: &reason,
}
// SentAmt returns 90, 10
// TerminalInfo returns nil, nil
// InFlightHTLCs returns 1
paymentActive := &channeldb.MPPayment{
HTLCs: []channeldb.HTLCAttempt{
makeActiveAttempt(100, 10),
makeFailedAttempt(100, 10),
},
}
testCases := []struct {
name string
payment *channeldb.MPPayment
@ -992,16 +966,31 @@ func TestUpdatePaymentState(t *testing.T) {
{
// Test that when the sentAmt exceeds totalAmount, the
// error is returned.
name: "amount exceeded error",
payment: paymentSettled,
name: "amount exceeded error",
// SentAmt returns 90, 10
// TerminalInfo returns non-nil, nil
// InFlightHTLCs returns 0
payment: &channeldb.MPPayment{
HTLCs: []channeldb.HTLCAttempt{
makeSettledAttempt(100, 10, preimage),
},
},
totalAmt: 1,
shouldReturnError: true,
},
{
// Test that when the fee budget is reached, the
// remaining fee should be zero.
name: "fee budget reached",
payment: paymentActive,
name: "fee budget reached",
payment: &channeldb.MPPayment{
// SentAmt returns 90, 10
// TerminalInfo returns nil, nil
// InFlightHTLCs returns 1
HTLCs: []channeldb.HTLCAttempt{
makeActiveAttempt(100, 10),
makeFailedAttempt(100, 10),
},
},
totalAmt: 1000,
feeLimit: 1,
expectedState: &paymentState{
@ -1014,8 +1003,15 @@ func TestUpdatePaymentState(t *testing.T) {
{
// Test when the payment is settled, the state should
// be marked as terminated.
name: "payment settled",
payment: paymentSettled,
name: "payment settled",
// SentAmt returns 90, 10
// TerminalInfo returns non-nil, nil
// InFlightHTLCs returns 0
payment: &channeldb.MPPayment{
HTLCs: []channeldb.HTLCAttempt{
makeSettledAttempt(100, 10, preimage),
},
},
totalAmt: 1000,
feeLimit: 100,
expectedState: &paymentState{
@ -1028,8 +1024,13 @@ func TestUpdatePaymentState(t *testing.T) {
{
// Test when the payment is failed, the state should be
// marked as terminated.
name: "payment failed",
payment: paymentFailed,
name: "payment failed",
// SentAmt returns 0, 0
// TerminalInfo returns nil, non-nil
// InFlightHTLCs returns 0
payment: &channeldb.MPPayment{
FailureReason: &failureReasonError,
},
totalAmt: 1000,
feeLimit: 100,
expectedState: &paymentState{