fuse/readonly/ipfs_test: fix t.Fatal in a goroutine
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
Dec 12, 2015 at 21:21 UTC
f14482265d87ce340e891fa30c8759387e6dbfb0
1 file changed
+17
-5
fuse/readonly/ipfs_test.go
+17
-5
@@ -4,6 +4,7 @@ package readonly
4
5
import (
6
"bytes"
7
+ "errors"
8
"fmt"
9
"io/ioutil"
10
"math/rand"
@@ -154,6 +155,7 @@ func TestIpfsStressRead(t *testing.T) {
155
156
// Now read a bunch, concurrently
157
wg := sync.WaitGroup{}
158
+ errs := make(chan error)
159
160
for s := 0; s < 4; s++ {
161
wg.Add(1)
@@ -165,26 +167,36 @@ func TestIpfsStressRead(t *testing.T) {
167
fname := path.Join(mnt.Dir, item)
168
rbuf, err := ioutil.ReadFile(fname)
169
if err != nil {
168
- t.Fatal(err)
170
+ errs <- err
171
}
172
173
read, err := coreunix.Cat(nd.Context(), nd, item)
174
if err != nil {
173
- t.Fatal(err)
175
+ errs <- err
176
}
177
178
data, err := ioutil.ReadAll(read)
179
if err != nil {
178
- t.Fatal(err)
180
+ errs <- err
181
}
182
183
if !bytes.Equal(rbuf, data) {
182
- t.Fatal("Incorrect Read!")
184
+ errs <- errors.New("Incorrect Read!")
185
}
186
}
187
}()
188
}
187
- wg.Wait()
189
+
190
+ go func() {
191
+ wg.Wait()
192
+ close(errs)
193
+ }()
194
+
195
+ for err := range errs {
196
+ if err != nil {
197
+ t.Fatal(err)
198
+ }
199
+ }
200
}
201
202
// Test writing a file and reading it back