提交 f1448226 作者: Christian Couder

fuse/readonly/ipfs_test: fix t.Fatal in a goroutine

License: MIT
Signed-off-by: 's avatarChristian Couder <chriscool@tuxfamily.org>
上级 f905197f
...@@ -4,6 +4,7 @@ package readonly ...@@ -4,6 +4,7 @@ package readonly
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
...@@ -154,6 +155,7 @@ func TestIpfsStressRead(t *testing.T) { ...@@ -154,6 +155,7 @@ func TestIpfsStressRead(t *testing.T) {
// Now read a bunch, concurrently // Now read a bunch, concurrently
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
errs := make(chan error)
for s := 0; s < 4; s++ { for s := 0; s < 4; s++ {
wg.Add(1) wg.Add(1)
...@@ -165,26 +167,36 @@ func TestIpfsStressRead(t *testing.T) { ...@@ -165,26 +167,36 @@ func TestIpfsStressRead(t *testing.T) {
fname := path.Join(mnt.Dir, item) fname := path.Join(mnt.Dir, item)
rbuf, err := ioutil.ReadFile(fname) rbuf, err := ioutil.ReadFile(fname)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
read, err := coreunix.Cat(nd.Context(), nd, item) read, err := coreunix.Cat(nd.Context(), nd, item)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
data, err := ioutil.ReadAll(read) data, err := ioutil.ReadAll(read)
if err != nil { if err != nil {
t.Fatal(err) errs <- err
} }
if !bytes.Equal(rbuf, data) { if !bytes.Equal(rbuf, data) {
t.Fatal("Incorrect Read!") errs <- errors.New("Incorrect Read!")
} }
} }
}() }()
} }
go func() {
wg.Wait() wg.Wait()
close(errs)
}()
for err := range errs {
if err != nil {
t.Fatal(err)
}
}
} }
// Test writing a file and reading it back // Test writing a file and reading it back
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论