-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconc_test.go
56 lines (47 loc) · 962 Bytes
/
conc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package goblin_test
import (
"bytes"
"fmt"
"os"
"sync"
"testing"
"github.com/ohait/goblin"
)
func TestConc(t *testing.T) {
//goblin.Logger = t.Logf
if testing.Short() {
t.SkipNow()
}
_ = os.RemoveAll("/tmp/test-goblin")
db, err := goblin.New("/tmp/test-goblin/")
noError(t, err)
t.Logf("init %+v", db)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
testConc(t, db)
}()
}
wg.Wait()
}
func testConc(t *testing.T, db *goblin.DB) {
data := make([]byte, 900)
for i := 0; i < len(data); i++ {
data[i] = byte('0' + (i % 26))
}
for i := 0; i < 1000; i++ {
err := db.Store(fmt.Sprint(i), data)
noError(t, err)
}
for i := 0; i < 1000; i++ {
x, err := db.Fetch(fmt.Sprint(i))
noError(t, err)
if bytes.Compare(x, data) != 0 {
t.Fatalf("expected\n%d %s got\n%d %s", len(data), string(data), len(x), string(x))
}
err = db.Store(fmt.Sprint(i), data)
noError(t, err)
}
}