Skip to content

Commit

Permalink
eth/fetcher: avoid hang in tests (partial fix for ethereum#23331) (et…
Browse files Browse the repository at this point in the history
…hereum#23351)

* eth/fetcher: fix test to avoid hanging. Partial fix for ethereum#23331

* eth/filters: avoid dangling goroutines

* eth/fetcher: revert closing of proceed
  • Loading branch information
holiman authored and unclezoro committed Sep 21, 2022
1 parent f781ea8 commit 8d19185
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 10 additions & 1 deletion eth/fetcher/tx_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions eth/filters/filter_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 8d19185

Please sign in to comment.