Skip to content

Commit 6cdfa57

Browse files
committed
test for concurrent writes in same dir
1 parent 395ff02 commit 6cdfa57

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

fuse/ipns/ipns_test.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ package ipns
55
import (
66
"bytes"
77
"crypto/rand"
8+
"fmt"
89
"io/ioutil"
910
"os"
11+
"sync"
1012
"testing"
1113

1214
fstest "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil"
@@ -64,7 +66,6 @@ func writeFileData(t *testing.T, data []byte, path string) []byte {
6466
}
6567

6668
func verifyFile(t *testing.T, path string, data []byte) {
67-
t.Logf("verify %s", path)
6869
fi, err := os.Open(path)
6970
if err != nil {
7071
t.Fatal(err)
@@ -305,6 +306,40 @@ func TestAppendFile(t *testing.T) {
305306
}
306307
}
307308

309+
func TestConcurrentWrites(t *testing.T) {
310+
if testing.Short() {
311+
t.SkipNow()
312+
}
313+
_, mnt := setupIpnsTest(t, nil)
314+
defer mnt.Close()
315+
316+
nactors := 4
317+
filesPerActor := 400
318+
fileSize := 2000
319+
320+
data := make([][][]byte, nactors)
321+
322+
wg := sync.WaitGroup{}
323+
for i := 0; i < nactors; i++ {
324+
data[i] = make([][]byte, filesPerActor)
325+
wg.Add(1)
326+
go func(n int) {
327+
defer wg.Done()
328+
for j := 0; j < filesPerActor; j++ {
329+
out := writeFile(t, fileSize, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", n, j))
330+
data[n][j] = out
331+
}
332+
}(i)
333+
}
334+
wg.Wait()
335+
336+
for i := 0; i < nactors; i++ {
337+
for j := 0; j < filesPerActor; j++ {
338+
verifyFile(t, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", i, j), data[i][j])
339+
}
340+
}
341+
}
342+
308343
/*
309344
func TestFastRepublish(t *testing.T) {
310345
if testing.Short() {

0 commit comments

Comments
 (0)