-
Notifications
You must be signed in to change notification settings - Fork 0
/
qps_set_test.go
73 lines (63 loc) · 3.54 KB
/
qps_set_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
package qube_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/winebarrel/qube"
)
func Test_QPSSet_Even(t *testing.T) {
assert := assert.New(t)
dps := []qube.DataPoint{
// 1 qps
{Time: time.Date(2023, 10, 11, 12, 13, 14, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 15, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 16, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
// 2 qps
{Time: time.Date(2023, 10, 11, 12, 13, 17, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 17, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond},
// 6 qps
{Time: time.Date(2023, 10, 11, 12, 13, 18, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond},
// 7 qps
{Time: time.Date(2023, 10, 11, 12, 13, 19, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 19, 6, time.UTC).Unix(), Duration: 1 * time.Millisecond},
}
qpsSet := qube.NewQPSSet(dps)
minQPS, maxQPS, medianQPS := qpsSet.Stats()
assert.Equal(float64(1), minQPS)
assert.Equal(float64(7), maxQPS)
assert.Equal(float64(4), medianQPS)
}
func Test_QPSSet_Odd(t *testing.T) {
assert := assert.New(t)
dps := []qube.DataPoint{
// 1 qps
{Time: time.Date(2023, 10, 11, 12, 13, 14, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 15, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 16, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
// 2 qps
{Time: time.Date(2023, 10, 11, 12, 13, 17, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 17, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond},
// 6 qps
{Time: time.Date(2023, 10, 11, 12, 13, 18, 0, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 1, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 2, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 3, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 4, time.UTC).Unix(), Duration: 1 * time.Millisecond},
{Time: time.Date(2023, 10, 11, 12, 13, 18, 5, time.UTC).Unix(), Duration: 1 * time.Millisecond},
}
qpsSet := qube.NewQPSSet(dps)
minQPS, maxQPS, medianQPS := qpsSet.Stats()
assert.Equal(float64(1), minQPS)
assert.Equal(float64(6), maxQPS)
assert.Equal(float64(1), medianQPS)
}