-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder_test.go
257 lines (243 loc) · 8.57 KB
/
recorder_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package qube_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/winebarrel/qube"
)
func Test_Recorder(t *testing.T) {
assert := assert.New(t)
options := &qube.Options{
AgentOptions: qube.AgentOptions{
Force: true,
},
DataOptions: qube.DataOptions{
DataFiles: []string{"data.jsonl"},
Key: "q",
Loop: true,
Random: false,
CommitRate: 0,
},
DBConfig: qube.DBConfig{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
Noop: false,
},
Nagents: 1,
Rate: 0,
Time: 1 * time.Second,
Progress: false,
}
deps := []qube.DataPointWithErr{
// 1 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 14, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 15, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 16, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 2 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 17, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 17, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 6 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 7 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 6, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
}
rec := qube.NewRecorder(testUUID, options)
rec.Start()
rec.Add(deps)
rec.Close()
report := rec.Report()
// Set dummy value
report.StartedAt = time.Time{}
report.FinishedAt = time.Time{}
report.ElapsedTime = 0
report.AvgQPS = 0
report.GOMAXPROCS = 10
assert.Equal(`{
"ID": "473d2574-4d1c-46cf-a275-5f3541eb47b7",
"StartedAt": "0001-01-01T00:00:00Z",
"FinishedAt": "0001-01-01T00:00:00Z",
"ElapsedTime": "0s",
"Options": {
"Force": true,
"DataFiles": [
"data.jsonl"
],
"Key": "q",
"Loop": true,
"Random": false,
"CommitRate": 0,
"DSN": "root@tcp(127.0.0.1:13306)/mysql",
"Driver": "mysql",
"Noop": false,
"Nagents": 1,
"Rate": 0,
"Time": "0s"
},
"GOMAXPROCS": 10,
"QueryCount": 18,
"ErrorQueryCount": 0,
"AvgQPS": 0,
"MaxQPS": 7,
"MinQPS": 1,
"MedianQPS": 4,
"Duration": {
"Count": 18,
"Histogram": [
{
"1ms - 1ms": 18
}
],
"Rate": {
"Second": 1000
},
"Samples": 18,
"Time": {
"Avg": "1ms",
"Cumulative": "18ms",
"HMean": "999.999µs",
"Long5p": "1ms",
"Max": "1ms",
"Min": "1ms",
"P50": "1ms",
"P75": "1ms",
"P95": "1ms",
"P99": "1ms",
"P999": "1ms",
"Range": "0s",
"Short5p": "1ms",
"StdDev": "0s"
}
}
}`, report.JSON())
}
func Test_Recorder_WithError(t *testing.T) {
assert := assert.New(t)
options := &qube.Options{
AgentOptions: qube.AgentOptions{
Force: true,
},
DataOptions: qube.DataOptions{
DataFiles: []string{"data.jsonl"},
Key: "q",
Loop: true,
Random: false,
CommitRate: 0,
},
DBConfig: qube.DBConfig{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
Noop: false,
},
Nagents: 1,
Rate: 0,
Time: 1 * time.Second,
Progress: false,
}
dpes := []qube.DataPointWithErr{
// 1 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 14, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 15, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 16, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 2 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 17, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 17, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 6 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 18, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// 7 qps
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 19, 6, time.UTC).Unix(), Duration: 1 * time.Millisecond}, false},
// error
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 20, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, true},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 21, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, true},
{qube.DataPoint{Time: time.Date(2023, 10, 11, 12, 13, 22, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond}, true},
}
rec := qube.NewRecorder(testUUID, options)
rec.Start()
rec.Add(dpes)
rec.Close()
report := rec.Report()
// Set dummy value
report.StartedAt = time.Time{}
report.FinishedAt = time.Time{}
report.ElapsedTime = 0
report.AvgQPS = 0
report.GOMAXPROCS = 10
assert.Equal(`{
"ID": "473d2574-4d1c-46cf-a275-5f3541eb47b7",
"StartedAt": "0001-01-01T00:00:00Z",
"FinishedAt": "0001-01-01T00:00:00Z",
"ElapsedTime": "0s",
"Options": {
"Force": true,
"DataFiles": [
"data.jsonl"
],
"Key": "q",
"Loop": true,
"Random": false,
"CommitRate": 0,
"DSN": "root@tcp(127.0.0.1:13306)/mysql",
"Driver": "mysql",
"Noop": false,
"Nagents": 1,
"Rate": 0,
"Time": "0s"
},
"GOMAXPROCS": 10,
"QueryCount": 21,
"ErrorQueryCount": 3,
"AvgQPS": 0,
"MaxQPS": 7,
"MinQPS": 1,
"MedianQPS": 4,
"Duration": {
"Count": 18,
"Histogram": [
{
"1ms - 1ms": 18
}
],
"Rate": {
"Second": 1000
},
"Samples": 18,
"Time": {
"Avg": "1ms",
"Cumulative": "18ms",
"HMean": "999.999µs",
"Long5p": "1ms",
"Max": "1ms",
"Min": "1ms",
"P50": "1ms",
"P75": "1ms",
"P95": "1ms",
"P99": "1ms",
"P999": "1ms",
"Range": "0s",
"Short5p": "1ms",
"StdDev": "0s"
}
}
}`, report.JSON())
}