From 2cf2e9955ba359bd56da0f8dea54efadce040ede Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 15 May 2020 12:12:01 +0300 Subject: [PATCH] lib/storage: wait for all the goroutines to finish in TestSearch in order to prevent racy behavior on test finish --- lib/storage/search_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/storage/search_test.go b/lib/storage/search_test.go index a7900a1ec1..de090d2a49 100644 --- a/lib/storage/search_test.go +++ b/lib/storage/search_test.go @@ -168,16 +168,20 @@ func testSearchGeneric(t *testing.T, forcePerDayInvertedIndex bool) { ch <- testSearchInternal(st, tr, mrs, accountsCount) }() } + var firstError error for i := 0; i < cap(ch); i++ { select { case err := <-ch: - if err != nil { - t.Fatalf("unexpected error: %s", err) + if err != nil && firstError == nil { + firstError = err } case <-time.After(10 * time.Second): t.Fatalf("timeout") } } + if firstError != nil { + t.Fatalf("unexpected error: %s", firstError) + } }) }