forked from viciious/go-tarantool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperfcount_test.go
69 lines (59 loc) · 1.46 KB
/
perfcount_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
package tarantool
import (
"expvar"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPerfCount(t *testing.T) {
perf := PerfCount{
expvar.NewInt("net_read"),
expvar.NewInt("net_write"),
expvar.NewInt("net_packets_in"),
expvar.NewInt("net_packets_out"),
nil,
nil,
}
assert := assert.New(t)
require := require.New(t)
config := `
local s = box.schema.space.create('tester', {id = 42})
box.schema.user.grant('guest', 'write', 'space', 'tester')
s:create_index('tester_id', {
type = 'hash',
parts = {1, 'NUM'}
})
`
box, err := NewBox(config, nil)
require.NoError(err)
defer box.Close()
conn, err := Connect(box.Addr(), &Options{
DefaultSpace: "tester",
Perf: perf,
})
require.NoError(err)
defer conn.Close()
_, err = conn.Execute(&Replace{
Tuple: []interface{}{int64(1)},
})
require.NoError(err)
nr := perf.NetRead.Value()
nw := perf.NetWrite.Value()
pin := perf.NetPacketsIn.Value()
pout := perf.NetPacketsOut.Value()
assert.True(nr > 0)
assert.True(nw > 0)
assert.True(pin > 0)
assert.True(pout > 0)
assert.True(nr >= pin)
assert.True(nw >= pout)
tuples, err := conn.Execute(&Select{
KeyTuple: []interface{}{int64(1)},
})
require.NoError(err)
assert.Equal([][]interface{}{{int64(1)}}, tuples)
assert.True(perf.NetRead.Value() > nr)
assert.True(perf.NetWrite.Value() > nw)
assert.Equal(pin+1, perf.NetPacketsIn.Value())
assert.Equal(pout+1, perf.NetPacketsOut.Value())
}