goroutines are back
License: MIT Signed-off-by: Max Chechel <hexdigest@gmail.com>
Max Chechel committed
Jan 14, 2019 at 21:56 UTC
71a177cf4bcffde193ac8136cee3fe3d6aeff0df
1 file changed
+26
-12
fuse/readonly/ipfs_test.go
+26
-12
@@ -5,13 +5,14 @@ package readonly
5
import (
6
"bytes"
7
"context"
8
+ "errors"
9
"fmt"
10
"io/ioutil"
11
"math/rand"
12
"os"
13
"path"
13
- "strconv"
14
"strings"
15
+ "sync"
16
"testing"
17
18
core "github.com/ipfs/go-ipfs/core"
@@ -163,22 +164,24 @@ func TestIpfsStressRead(t *testing.T) {
164
paths = append(paths, npaths...)
165
}
166
166
- t.Parallel()
167
+ // Now read a bunch, concurrently
168
+ wg := sync.WaitGroup{}
169
+ errs := make(chan error)
170
171
for s := 0; s < 4; s++ {
169
- t.Run(strconv.Itoa(s), func(t *testing.T) {
172
+ wg.Add(1)
173
+ go func() {
174
+ defer wg.Done()
175
+
176
for i := 0; i < 2000; i++ {
171
- item, err := iface.ParsePath(paths[rand.Intn(len(paths))])
172
- if err != nil {
173
- t.Fatal(err)
174
- }
177
+ item, _ := iface.ParsePath(paths[rand.Intn(len(paths))])
178
179
relpath := strings.Replace(item.String(), item.Namespace(), "", 1)
180
fname := path.Join(mnt.Dir, relpath)
181
182
rbuf, err := ioutil.ReadFile(fname)
183
if err != nil {
181
- t.Fatal(err)
184
+ errs <- err
185
}
186
187
//nd.Context() is never closed which leads to
@@ -187,21 +190,32 @@ func TestIpfsStressRead(t *testing.T) {
190
191
read, err := api.Unixfs().Get(ctx, item)
192
if err != nil {
190
- t.Fatal(err)
193
+ errs <- err
194
}
195
196
data, err := ioutil.ReadAll(read.(files.File))
197
if err != nil {
195
- t.Fatal(err)
198
+ errs <- err
199
}
200
201
cancelFunc()
202
203
if !bytes.Equal(rbuf, data) {
201
- t.Fatal("incorrect read")
204
+ errs <- errors.New("incorrect read")
205
}
206
}
204
- })
207
+ }()
208
+ }
209
+
210
+ go func() {
211
+ wg.Wait()
212
+ close(errs)
213
+ }()
214
+
215
+ for err := range errs {
216
+ if err != nil {
217
+ t.Fatal(err)
218
+ }
219
}
220
}
221