stress test for ipfs fuse
Jeromy committed
Feb 23, 2015 at 23:33 UTC
36a21561f772584f8c2e7966c978d8bbf8347e98
2 files changed
+104
-8
core/mock.go
+2
@@ -1,6 +1,7 @@
1
package core
2
3
import (
4
+ ctxgroup "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
5
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
6
syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
7
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
@@ -39,6 +40,7 @@ func NewMockNode() (*IpfsNode, error) {
40
nd.Peerstore = peer.NewPeerstore()
41
nd.Peerstore.AddPrivKey(p, ident.PrivateKey())
42
nd.Peerstore.AddPubKey(p, ident.PublicKey())
43
+ nd.ContextGroup = ctxgroup.WithContext(ctx)
44
45
nd.PeerHost, err = mocknet.New(ctx).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
46
if err != nil {
fuse/readonly/ipfs_test.go
+102
-8
@@ -2,16 +2,18 @@ package readonly
2
3
import (
4
"bytes"
5
- "crypto/rand"
6
- //context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
5
+ "fmt"
6
"io/ioutil"
7
+ "math/rand"
8
"os"
9
"path"
10
+ "sync"
11
"testing"
12
13
fstest "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil"
14
15
core "github.com/jbenet/go-ipfs/core"
16
+ coreunix "github.com/jbenet/go-ipfs/core/coreunix"
17
importer "github.com/jbenet/go-ipfs/importer"
18
chunk "github.com/jbenet/go-ipfs/importer/chunk"
19
dag "github.com/jbenet/go-ipfs/merkledag"
@@ -26,12 +28,6 @@ func maybeSkipFuseTests(t *testing.T) {
28
}
29
}
30
29
-func randBytes(size int) []byte {
30
- b := make([]byte, size)
31
- rand.Read(b)
32
- return b
33
-}
34
-
31
func randObj(t *testing.T, nd *core.IpfsNode, size int64) (*dag.Node, []byte) {
32
buf := make([]byte, size)
33
u.NewTimeSeededRand().Read(buf)
@@ -89,6 +85,104 @@ func TestIpfsBasicRead(t *testing.T) {
85
}
86
}
87
88
+func getPaths(t *testing.T, ipfs *core.IpfsNode, name string, n *dag.Node) []string {
89
+ if len(n.Links) == 0 {
90
+ return []string{name}
91
+ }
92
+ var out []string
93
+ for _, lnk := range n.Links {
94
+ child, err := lnk.GetNode(ipfs.DAG)
95
+ if err != nil {
96
+ t.Fatal(err)
97
+ }
98
+ sub := getPaths(t, ipfs, path.Join(name, lnk.Name), child)
99
+ out = append(out, sub...)
100
+ }
101
+ return out
102
+}
103
+
104
+// Perform a large number of concurrent reads to stress the system
105
+func TestIpfsStressRead(t *testing.T) {
106
+ if testing.Short() {
107
+ t.SkipNow()
108
+ }
109
+ nd, mnt := setupIpfsTest(t, nil)
110
+ defer mnt.Close()
111
+
112
+ var ks []u.Key
113
+ var paths []string
114
+
115
+ nobj := 50
116
+ ndiriter := 50
117
+
118
+ // Make a bunch of objects
119
+ for i := 0; i < nobj; i++ {
120
+ fi, _ := randObj(t, nd, rand.Int63n(50000))
121
+ k, err := fi.Key()
122
+ if err != nil {
123
+ t.Fatal(err)
124
+ }
125
+
126
+ ks = append(ks, k)
127
+ paths = append(paths, k.String())
128
+ }
129
+
130
+ // Now make a bunch of dirs
131
+ for i := 0; i < ndiriter; i++ {
132
+ db := uio.NewDirectory(nd.DAG)
133
+ for j := 0; j < 1+rand.Intn(10); j++ {
134
+ name := fmt.Sprintf("child%d", j)
135
+ err := db.AddChild(name, ks[rand.Intn(len(ks))])
136
+ if err != nil {
137
+ t.Fatal(err)
138
+ }
139
+ }
140
+ newdir := db.GetNode()
141
+ k, err := nd.DAG.Add(newdir)
142
+ if err != nil {
143
+ t.Fatal(err)
144
+ }
145
+
146
+ ks = append(ks, k)
147
+ npaths := getPaths(t, nd, k.String(), newdir)
148
+ paths = append(paths, npaths...)
149
+ }
150
+
151
+ // Now read a bunch, concurrently
152
+ wg := sync.WaitGroup{}
153
+
154
+ for s := 0; s < 4; s++ {
155
+ wg.Add(1)
156
+ go func() {
157
+ defer wg.Done()
158
+
159
+ for i := 0; i < 2000; i++ {
160
+ item := paths[rand.Intn(len(paths))]
161
+ fname := path.Join(mnt.Dir, item)
162
+ rbuf, err := ioutil.ReadFile(fname)
163
+ if err != nil {
164
+ t.Fatal(err)
165
+ }
166
+
167
+ read, err := coreunix.Cat(nd, item)
168
+ if err != nil {
169
+ t.Fatal(err)
170
+ }
171
+
172
+ data, err := ioutil.ReadAll(read)
173
+ if err != nil {
174
+ t.Fatal(err)
175
+ }
176
+
177
+ if !bytes.Equal(rbuf, data) {
178
+ t.Fatal("Incorrect Read!")
179
+ }
180
+ }
181
+ }()
182
+ }
183
+ wg.Wait()
184
+}
185
+
186
// Test writing a file and reading it back
187
func TestIpfsBasicDirRead(t *testing.T) {
188
if testing.Short() {