routing: fix race in TestSendMPPaymentFailed

This commit is contained in:
yyforyongyu 2021-07-27 13:12:03 +08:00
parent ebabda6717
commit 46747057c3
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
2 changed files with 10 additions and 8 deletions

View File

@ -591,8 +591,6 @@ func (m *mockPaymentSessionSource) NewPaymentSessionEmpty() PaymentSession {
type mockMissionControl struct {
mock.Mock
failReason *channeldb.FailureReason
}
var _ MissionController = (*mockMissionControl)(nil)
@ -603,7 +601,13 @@ func (m *mockMissionControl) ReportPaymentFail(
*channeldb.FailureReason, error) {
args := m.Called(paymentID, rt, failureSourceIdx, failure)
return m.failReason, args.Error(1)
// Type assertion on nil will fail, so we check and return here.
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*channeldb.FailureReason), args.Error(1)
}
func (m *mockMissionControl) ReportPaymentSuccess(paymentID uint64,

View File

@ -4023,17 +4023,16 @@ func TestSendMPPaymentFailed(t *testing.T) {
failureReason := channeldb.FailureReasonPaymentDetails
missionControl.On("ReportPaymentFail",
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(nil, nil).Run(func(args mock.Arguments) {
).Return(&failureReason, nil).Run(func(args mock.Arguments) {
// We only return the terminal error once, thus when the method
// is called, we will return it with a nil error.
if called {
missionControl.failReason = nil
args[0] = nil
return
}
// If it's the first time calling this method, we will return a
// terminal error.
missionControl.failReason = &failureReason
payment.FailureReason = &failureReason
called = true
})
@ -4213,8 +4212,7 @@ func TestSendMPPaymentFailedWithShardsInFlight(t *testing.T) {
failureReason := channeldb.FailureReasonPaymentDetails
missionControl.On("ReportPaymentFail",
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(failureReason, nil).Run(func(args mock.Arguments) {
missionControl.failReason = &failureReason
).Return(&failureReason, nil).Run(func(args mock.Arguments) {
payment.FailureReason = &failureReason
}).Once()