From 5b4ac113711baf033c1692eeec0c6a4b5292e034 Mon Sep 17 00:00:00 2001 From: Arran Schlosberg Date: Thu, 28 Nov 2024 12:53:44 +0000 Subject: [PATCH] test: block on `terminate(false)` instead of `wait()` This is effectively the same thing as both wait on `<-sf.term` but it makes for a clearer test that demonstrates the bug because `terminate(false)` is documented as blocking until "all disk loads finish". --- core/state/trie_prefetcher_test.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/state/trie_prefetcher_test.go b/core/state/trie_prefetcher_test.go index dd99b5e1b0..655ffc3544 100644 --- a/core/state/trie_prefetcher_test.go +++ b/core/state/trie_prefetcher_test.go @@ -83,7 +83,7 @@ func TestSchdeulerTerminationRaceCondition(t *testing.T) { var wg sync.WaitGroup for i := 0; i < 50_000; i++ { - wg.Add(3) + wg.Add(2) fetcher := newSubfetcher(db.db, db.originalRoot, common.Hash{}, db.originalRoot, common.Address{}) var gotScheduleErr error @@ -98,16 +98,11 @@ func TestSchdeulerTerminationRaceCondition(t *testing.T) { go func() { defer wg.Done() <-start - fetcher.terminate(false) - }() + fetcher.terminate(false /*async*/) - go func() { - defer wg.Done() <-doneScheduling - fetcher.wait() - if gotScheduleErr == nil && len(fetcher.tasks) > 0 { - t.Errorf("%T.schedule() returned nil error but %d task(s) remain in queue after %T.wait() returned", fetcher, len(fetcher.tasks), fetcher) + t.Errorf("%T.schedule() returned nil error but %d task(s) remain in queue after %T.terminate([blocking]) returned", fetcher, len(fetcher.tasks), fetcher) } }() }