mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
routing/test: close payment result channel on shutdown, mimicking switch
This commit updates our mock to more closely follow the behavior of the switch for mocked calls to GetPaymentResult. As it stands, our tests send a test-created error from the switch when we want to mock shutdown. In reality, the switch will close its result channel, so we update this test to follow that behavior. This matters for the commit that follows, because we start checking the error our payments return. If we have an error from the switch, our tests will fail with an error that we do not encounter in practice.
This commit is contained in:
@@ -155,10 +155,9 @@ func (m *mockPaymentSession) RequestRoute(_, _ lnwire.MilliSatoshi,
|
||||
}
|
||||
|
||||
type mockPayer struct {
|
||||
sendResult chan error
|
||||
paymentResultErr chan error
|
||||
paymentResult chan *htlcswitch.PaymentResult
|
||||
quit chan struct{}
|
||||
sendResult chan error
|
||||
paymentResult chan *htlcswitch.PaymentResult
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
var _ PaymentAttemptDispatcher = (*mockPayer)(nil)
|
||||
@@ -180,12 +179,16 @@ func (m *mockPayer) GetPaymentResult(paymentID uint64, _ lntypes.Hash,
|
||||
_ htlcswitch.ErrorDecrypter) (<-chan *htlcswitch.PaymentResult, error) {
|
||||
|
||||
select {
|
||||
case res := <-m.paymentResult:
|
||||
case res, ok := <-m.paymentResult:
|
||||
resChan := make(chan *htlcswitch.PaymentResult, 1)
|
||||
resChan <- res
|
||||
if !ok {
|
||||
close(resChan)
|
||||
} else {
|
||||
resChan <- res
|
||||
}
|
||||
|
||||
return resChan, nil
|
||||
case err := <-m.paymentResultErr:
|
||||
return nil, err
|
||||
|
||||
case <-m.quit:
|
||||
return nil, fmt.Errorf("test quitting")
|
||||
}
|
||||
|
Reference in New Issue
Block a user