Skip to content

Commit 35102e7

Browse files
authored
Merge pull request #9652 from Roasbeef/rbf-iteration-loop-flake
lnwallet/chancloser: fix flake in TestRbfCloseClosingNegotiationLocal
2 parents c33fbfb + eb863e4 commit 35102e7

File tree

2 files changed

+107
-83
lines changed

2 files changed

+107
-83
lines changed

lnwallet/chancloser/mock.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package chancloser
22

33
import (
44
"sync/atomic"
5+
"testing"
56

67
"github.com/btcsuite/btcd/btcec/v2"
78
"github.com/btcsuite/btcd/btcutil"
@@ -140,10 +141,32 @@ func (m *mockChanObserver) DisableChannel() error {
140141

141142
type mockErrorReporter struct {
142143
mock.Mock
144+
errorReported chan error
145+
}
146+
147+
// newMockErrorReporter creates a new mockErrorReporter.
148+
func newMockErrorReporter(t *testing.T) *mockErrorReporter {
149+
return &mockErrorReporter{
150+
// Buffer of 1 allows ReportError to send without blocking
151+
// if the test isn't immediately ready to receive.
152+
errorReported: make(chan error, 1),
153+
}
143154
}
144155

145156
func (m *mockErrorReporter) ReportError(err error) {
157+
// Keep existing behavior of forwarding to mock.Mock
146158
m.Called(err)
159+
160+
// Non-blockingly send the error to the channel.
161+
select {
162+
case m.errorReported <- err:
163+
164+
// If the channel is full or no one is listening, this prevents
165+
// ReportError from blocking. This might happen if ReportError is called
166+
// multiple times and the test only waits for the first, or if the test
167+
// times out waiting.
168+
default:
169+
}
147170
}
148171

149172
type mockCloseSigner struct {

0 commit comments

Comments
 (0)