eth/filters: fix flaky TestPendingTxFilterDeadlock

The test polls GetFilterChanges with a 100ms filter timeout. On a loaded
system a >100ms gap between two polls lets the timeout loop uninstall
the filter, so the next poll returns errFilterNotFound and the test
fails. Treat that as a benign early timeout, gated on the deadline
having actually elapsed; the uninstall is still verified through the
sub.Err() wait at the end of the test. Also close the done channel so
the tx-sending goroutine exits when the test finishes instead of
spinning for the remainder of the test binary.

Signed-off-by: Mikhail Kuznetsov <mikhail.n.kuznetsov@gmail.com>
This commit is contained in:
Mikhail Kuznetsov 2026-07-10 09:08:10 +04:00
parent 111e7b8b48
commit ebdbe5401f
No known key found for this signature in database

View file

@ -731,6 +731,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
api = NewFilterAPI(sys)
done = make(chan struct{})
)
defer close(done)
go func() {
// Bombard feed with txes until signal was received to stop
@ -752,6 +753,7 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
// timeout either in 100ms or 200ms
subs := make([]*Subscription, 20)
for i := range subs {
created := time.Now()
fid := api.NewPendingTransactionFilter(nil)
api.filtersMu.Lock()
f, ok := api.filters[fid]
@ -763,6 +765,14 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
// Wait for at least one tx to arrive in filter
for {
hashes, err := api.GetFilterChanges(fid)
if errors.Is(err, errFilterNotFound) && time.Since(created) >= timeout {
// The filter was not polled for longer than the configured
// timeout and has already been uninstalled. This can happen
// on a loaded system and is not a deadlock: the uninstall
// is verified through sub.Err() below. The time check keeps
// this tolerance from masking uninstalls before the deadline.
break
}
if err != nil {
t.Fatalf("Filter should exist: %v\n", err)
}