Commit 95afd3c2 authored by Christian Couder's avatar Christian Couder

merkledag/merkledag_test: fix t.Fatal in a goroutine

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent 548ae27c
...@@ -2,6 +2,7 @@ package merkledag_test ...@@ -2,6 +2,7 @@ package merkledag_test
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -193,32 +194,43 @@ func runBatchFetchTest(t *testing.T, read io.Reader) { ...@@ -193,32 +194,43 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
errs := make(chan error)
for i := 1; i < len(dagservs); i++ { for i := 1; i < len(dagservs); i++ {
wg.Add(1) wg.Add(1)
go func(i int) { go func(i int) {
defer wg.Done() defer wg.Done()
first, err := dagservs[i].Get(ctx, k) first, err := dagservs[i].Get(ctx, k)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
fmt.Println("Got first node back.") fmt.Println("Got first node back.")
read, err := uio.NewDagReader(ctx, first, dagservs[i]) read, err := uio.NewDagReader(ctx, first, dagservs[i])
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
datagot, err := ioutil.ReadAll(read) datagot, err := ioutil.ReadAll(read)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
if !bytes.Equal(datagot, expected) { if !bytes.Equal(datagot, expected) {
t.Fatal("Got bad data back!") errs <- errors.New("Got bad data back!")
} }
}(i) }(i)
} }
wg.Wait() go func() {
wg.Wait()
close(errs)
}()
for err := range errs {
if err != nil {
t.Fatal(err)
}
}
} }
func TestRecursiveAdd(t *testing.T) { func TestRecursiveAdd(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment