mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
Merge pull request #7336 from positiveblue/fix-race-condition
routing: fix reace condition in `TestUpdatePaymentState`
This commit is contained in:
commit
716febc6c7
2 changed files with 40 additions and 36 deletions
|
@ -219,6 +219,9 @@ data.
|
||||||
|
|
||||||
* [Fix gomnd linter error](https://github.com/lightningnetwork/lnd/pull/7325)
|
* [Fix gomnd linter error](https://github.com/lightningnetwork/lnd/pull/7325)
|
||||||
|
|
||||||
|
* [Fix race condition in
|
||||||
|
`TestUpdatePaymentState`](https://github.com/lightningnetwork/lnd/pull/7336)
|
||||||
|
|
||||||
## `lncli`
|
## `lncli`
|
||||||
|
|
||||||
* [Add an `insecure` flag to skip tls auth as well as a `metadata` string slice
|
* [Add an `insecure` flag to skip tls auth as well as a `metadata` string slice
|
||||||
|
|
|
@ -938,40 +938,14 @@ func TestUpdatePaymentState(t *testing.T) {
|
||||||
|
|
||||||
// paymentHash is the identifier on paymentLifecycle.
|
// paymentHash is the identifier on paymentLifecycle.
|
||||||
paymentHash := lntypes.Hash{}
|
paymentHash := lntypes.Hash{}
|
||||||
|
preimage := lntypes.Preimage{}
|
||||||
|
failureReasonError := channeldb.FailureReasonError
|
||||||
|
|
||||||
// TODO(yy): make MPPayment into an interface so we can mock it. The
|
// TODO(yy): make MPPayment into an interface so we can mock it. The
|
||||||
// current design implicitly tests the methods SendAmt, TerminalInfo,
|
// current design implicitly tests the methods SendAmt, TerminalInfo,
|
||||||
// and InFlightHTLCs on channeldb.MPPayment, which is not good. Once
|
// and InFlightHTLCs on channeldb.MPPayment, which is not good. Once
|
||||||
// MPPayment becomes an interface, we can then mock these methods here.
|
// 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 {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
payment *channeldb.MPPayment
|
payment *channeldb.MPPayment
|
||||||
|
@ -992,16 +966,31 @@ func TestUpdatePaymentState(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Test that when the sentAmt exceeds totalAmount, the
|
// Test that when the sentAmt exceeds totalAmount, the
|
||||||
// error is returned.
|
// error is returned.
|
||||||
name: "amount exceeded error",
|
name: "amount exceeded error",
|
||||||
payment: paymentSettled,
|
// SentAmt returns 90, 10
|
||||||
|
// TerminalInfo returns non-nil, nil
|
||||||
|
// InFlightHTLCs returns 0
|
||||||
|
payment: &channeldb.MPPayment{
|
||||||
|
HTLCs: []channeldb.HTLCAttempt{
|
||||||
|
makeSettledAttempt(100, 10, preimage),
|
||||||
|
},
|
||||||
|
},
|
||||||
totalAmt: 1,
|
totalAmt: 1,
|
||||||
shouldReturnError: true,
|
shouldReturnError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that when the fee budget is reached, the
|
// Test that when the fee budget is reached, the
|
||||||
// remaining fee should be zero.
|
// remaining fee should be zero.
|
||||||
name: "fee budget reached",
|
name: "fee budget reached",
|
||||||
payment: paymentActive,
|
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,
|
totalAmt: 1000,
|
||||||
feeLimit: 1,
|
feeLimit: 1,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
|
@ -1014,8 +1003,15 @@ func TestUpdatePaymentState(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Test when the payment is settled, the state should
|
// Test when the payment is settled, the state should
|
||||||
// be marked as terminated.
|
// be marked as terminated.
|
||||||
name: "payment settled",
|
name: "payment settled",
|
||||||
payment: paymentSettled,
|
// SentAmt returns 90, 10
|
||||||
|
// TerminalInfo returns non-nil, nil
|
||||||
|
// InFlightHTLCs returns 0
|
||||||
|
payment: &channeldb.MPPayment{
|
||||||
|
HTLCs: []channeldb.HTLCAttempt{
|
||||||
|
makeSettledAttempt(100, 10, preimage),
|
||||||
|
},
|
||||||
|
},
|
||||||
totalAmt: 1000,
|
totalAmt: 1000,
|
||||||
feeLimit: 100,
|
feeLimit: 100,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
|
@ -1028,8 +1024,13 @@ func TestUpdatePaymentState(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Test when the payment is failed, the state should be
|
// Test when the payment is failed, the state should be
|
||||||
// marked as terminated.
|
// marked as terminated.
|
||||||
name: "payment failed",
|
name: "payment failed",
|
||||||
payment: paymentFailed,
|
// SentAmt returns 0, 0
|
||||||
|
// TerminalInfo returns nil, non-nil
|
||||||
|
// InFlightHTLCs returns 0
|
||||||
|
payment: &channeldb.MPPayment{
|
||||||
|
FailureReason: &failureReasonError,
|
||||||
|
},
|
||||||
totalAmt: 1000,
|
totalAmt: 1000,
|
||||||
feeLimit: 100,
|
feeLimit: 100,
|
||||||
expectedState: &paymentState{
|
expectedState: &paymentState{
|
||||||
|
|
Loading…
Add table
Reference in a new issue