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
22
33import (
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
141142type 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
145156func (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
149172type mockCloseSigner struct {
You can’t perform that action at this time.
0 commit comments