From 7175f82495e5aaa92c0ddf544d6d8131eeaf5ca3 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 6 May 2022 15:23:43 +0200 Subject: [PATCH] eth/fetcher: avoid hang in tests (partial fix for #23331) (#23351) * eth/fetcher: fix test to avoid hanging. Partial fix for #23331 * eth/filters: avoid dangling goroutines * eth/fetcher: revert closing of proceed --- eth/fetcher/tx_fetcher_test.go | 11 ++++++++++- eth/filters/filter_system_test.go | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/eth/fetcher/tx_fetcher_test.go b/eth/fetcher/tx_fetcher_test.go index 796d4caf0f..e13d68ffd1 100644 --- a/eth/fetcher/tx_fetcher_test.go +++ b/eth/fetcher/tx_fetcher_test.go @@ -304,7 +304,6 @@ func TestTransactionFetcherSingletonRequesting(t *testing.T) { func TestTransactionFetcherFailedRescheduling(t *testing.T) { // Create a channel to control when tx requests can fail proceed := make(chan struct{}) - testTransactionFetcherParallel(t, txFetcherTest{ init: func() *TxFetcher { return NewTxFetcher( @@ -1263,6 +1262,16 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) { fetcher.Start() defer fetcher.Stop() + defer func() { // drain the wait chan on exit + for { + select { + case <-wait: + default: + return + } + } + }() + // Crunch through all the test steps and execute them for i, step := range tt.steps { switch step := step.(type) { diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index efeab58d7d..87971d5a97 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -301,12 +301,15 @@ func TestLogFilterCreation(t *testing.T) { ) for i, test := range testCases { - _, err := api.NewFilter(test.crit) - if test.success && err != nil { + id, err := api.NewFilter(test.crit) + if err != nil && test.success { t.Errorf("expected filter creation for case %d to success, got %v", i, err) } - if !test.success && err == nil { - t.Errorf("expected testcase %d to fail with an error", i) + if err == nil { + api.UninstallFilter(id) + if !test.success { + t.Errorf("expected testcase %d to fail with an error", i) + } } } }