From f905197fa5ef68e7094cbd3b290068dfb774d495 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 12 Dec 2015 21:04:21 +0100 Subject: [PATCH] exchange/bitswap/bitswap_test: fix t.Fatal in a goroutine License: MIT Signed-off-by: Christian Couder --- exchange/bitswap/bitswap_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exchange/bitswap/bitswap_test.go b/exchange/bitswap/bitswap_test.go index c6de90d78..3a2dba62f 100644 --- a/exchange/bitswap/bitswap_test.go +++ b/exchange/bitswap/bitswap_test.go @@ -168,19 +168,31 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) { t.Log("Distribute!") wg := sync.WaitGroup{} + errs := make(chan error) + for _, inst := range instances[1:] { wg.Add(1) go func(inst Instance) { defer wg.Done() outch, err := inst.Exchange.GetBlocks(ctx, blkeys) if err != nil { - t.Fatal(err) + errs <- err } for _ = range outch { } }(inst) } - wg.Wait() + + go func() { + wg.Wait() + close(errs) + }() + + for err := range errs { + if err != nil { + t.Fatal(err) + } + } t.Log("Verify!")