提交 c0ab4331 作者: Max Chechel

Fixed and cleaned up TestIpfsStressRead

License: MIT
Signed-off-by: 's avatarMax Chechel <hexdigest@gmail.com>
上级 1e9a638a
......@@ -4,13 +4,14 @@ package readonly
import (
"bytes"
"errors"
"context"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path"
"sync"
"strconv"
"strings"
"testing"
core "github.com/ipfs/go-ipfs/core"
......@@ -162,49 +163,45 @@ func TestIpfsStressRead(t *testing.T) {
paths = append(paths, npaths...)
}
// Now read a bunch, concurrently
wg := sync.WaitGroup{}
errs := make(chan error)
t.Parallel()
for s := 0; s < 4; s++ {
wg.Add(1)
go func() {
defer wg.Done()
t.Run(strconv.Itoa(s), func(t *testing.T) {
for i := 0; i < 2000; i++ {
item, _ := iface.ParsePath(paths[rand.Intn(len(paths))])
fname := path.Join(mnt.Dir, item.String())
item, err := iface.ParsePath(paths[rand.Intn(len(paths))])
if err != nil {
t.Fatal(err)
}
relpath := strings.Replace(item.String(), "/ipfs/", "/", 1)
fname := path.Join(mnt.Dir, relpath)
rbuf, err := ioutil.ReadFile(fname)
if err != nil {
errs <- err
t.Fatal(err)
}
read, err := api.Unixfs().Get(nd.Context(), item)
//nd.Context() is never closed which leads to
//hitting 8128 goroutine limit in go test -race mode
ctx, cancelFunc := context.WithCancel(context.Background())
read, err := api.Unixfs().Get(ctx, item)
if err != nil {
errs <- err
t.Fatal(err)
}
data, err := ioutil.ReadAll(read.(files.File))
if err != nil {
errs <- err
t.Fatal(err)
}
cancelFunc()
if !bytes.Equal(rbuf, data) {
errs <- errors.New("incorrect read")
}
}
}()
t.Fatal("incorrect read")
}
go func() {
wg.Wait()
close(errs)
}()
for err := range errs {
if err != nil {
t.Fatal(err)
}
})
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论