lnwallet/chancloser: fix fllake in TestRbfCloseClosingNegotiationLocal/send_offer_rbf_wrong_local_script

In this commit, we fix a flake in the
`TestRbfCloseClosingNegotiationLocal/send_offer_rbf_wrong_local_script`
test.

This flake can happen if the test shuts down _before_ the state machine
is actually able to process the sent event. In this case, the
expectations are triggered, and we find that the error isn't sent.

To resolve this, we create a new wrapper function that'll use a sync
channel send to assert that the error has been sent before we exit the
test.
This commit is contained in:
Olaoluwa Osuntokun committed 2025-06-10 18:44:34 -07:00
1 parent 40f58da161
commit eb863e46af
2 files changed
+87 -63

No files matched your search

+23
View File
@@ -2,6 +2,7 @@ package chancloser
import (
"sync/atomic"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
@@ -140,10 +141,32 @@ func (m *mockChanObserver) DisableChannel() error {
type mockErrorReporter struct {
mock.Mock
errorReported chan error
}
// newMockErrorReporter creates a new mockErrorReporter.
func newMockErrorReporter(t *testing.T) *mockErrorReporter {
return &mockErrorReporter{
// Buffer of 1 allows ReportError to send without blocking
// if the test isn't immediately ready to receive.
errorReported: make(chan error, 1),
}
}
func (m *mockErrorReporter) ReportError(err error) {
// Keep existing behavior of forwarding to mock.Mock
m.Called(err)
// Non-blockingly send the error to the channel.
select {
case m.errorReported <- err:
// If the channel is full or no one is listening, this prevents
// ReportError from blocking. This might happen if ReportError is called
// multiple times and the test only waits for the first, or if the test
// times out waiting.
default:
}
}
type mockCloseSigner struct {