File tree Expand file tree Collapse file tree 2 files changed +107
-83
lines changed Expand file tree Collapse file tree 2 files changed +107
-83
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package chancloser
2
2
3
3
import (
4
4
"sync/atomic"
5
+ "testing"
5
6
6
7
"github.com/btcsuite/btcd/btcec/v2"
7
8
"github.com/btcsuite/btcd/btcutil"
@@ -140,10 +141,32 @@ func (m *mockChanObserver) DisableChannel() error {
140
141
141
142
type mockErrorReporter struct {
142
143
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
+ }
143
154
}
144
155
145
156
func (m * mockErrorReporter ) ReportError (err error ) {
157
+ // Keep existing behavior of forwarding to mock.Mock
146
158
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
+ }
147
170
}
148
171
149
172
type mockCloseSigner struct {
You can’t perform that action at this time.
0 commit comments