This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stress_test.go
81 lines (68 loc) · 1.66 KB
/
stress_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package goBolt
import (
"fmt"
"github.com/mindstand/go-bolt/bolt_mode"
"github.com/mindstand/go-bolt/log"
"github.com/stretchr/testify/require"
"sync"
"testing"
)
func TestStress(t *testing.T) {
t.Skip()
log.SetLevel("info")
req := require.New(t)
client, err := NewClient(WithBasicAuth("neo4j", "changeme"), WithHostPort("0.0.0.0", 7687))
req.Nil(err)
req.NotNil(client)
log.Infof("opening driver")
driver, err := client.NewDriverPool(20)
req.Nil(err)
req.NotNil(driver)
defer driver.Close()
numThreads := 10
var wg sync.WaitGroup
for i := 0; i < numThreads; i++ {
wg.Add(1)
go driverCycle(driver, req, i, &wg)
}
wg.Wait()
}
func driverCycle(driver IDriverPool, req *require.Assertions, iter int, wg *sync.WaitGroup) {
log.Info("starting")
read := false
cycle := 0
for cycle != 15000 {
if read {
log.Infof("reading %v", iter)
conn, err := driver.Open(bolt_mode.ReadMode)
req.Nil(err)
req.NotNil(conn)
res, meta, err := conn.Query("match (n) return n limit 50", nil)
req.Nil(err)
req.NotNil(res)
req.NotNil(meta)
req.Nil(driver.Reclaim(conn))
log.Infof("done reading %v", iter)
} else {
log.Infof("writing %v", iter)
conn, err := driver.Open(bolt_mode.WriteMode)
req.Nil(err)
req.NotNil(conn)
tx, err := conn.Begin()
req.Nil(err)
req.NotNil(tx)
res, err := tx.Exec("merge (:TestNode{num:$num})", map[string]interface{}{
"num": fmt.Sprintf("%v-%v", iter, cycle),
})
req.Nil(err)
req.NotNil(res)
req.Nil(tx.Commit())
req.Nil(driver.Reclaim(conn))
log.Infof("done writing %v", iter)
}
cycle++
read = !read
}
log.Infof("completed [%v] cycles [%v]", cycle, iter)
wg.Done()
}