-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_test.go
88 lines (74 loc) · 2.2 KB
/
e2e_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
package traffic_test
import (
"sync/atomic"
. "github.com/crowdriff/traffic"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Generator", func() {
It("should be able to add 2 patterns with 50/50% prob", func() {
g := NewGenerator(1000, 1)
Ω(g).ShouldNot(BeNil())
var first, second uint32
g.AddPattern(NewPattern(50, func() {
atomic.AddUint32(&first, 1)
}))
g.AddPattern(NewPattern(50, func() {
atomic.AddUint32(&second, 1)
}))
g.Execute()
var lower uint32 = 450
var upper uint32 = 550
Ω(first).Should(BeNumerically(">=", lower))
Ω(first).Should(BeNumerically("<=", upper))
Ω(second).Should(BeNumerically(">=", lower))
Ω(second).Should(BeNumerically("<=", upper))
})
It("should be able to add 4 patterns with 25% prob each", func() {
// Prep
g := NewGenerator(10000, 1)
Ω(g).ShouldNot(BeNil())
var first, second, third, fourth uint32
g.AddPattern(NewPattern(25, func() {
atomic.AddUint32(&first, 1)
}))
g.AddPattern(NewPattern(25, func() {
atomic.AddUint32(&second, 1)
}))
g.AddPattern(NewPattern(25, func() {
atomic.AddUint32(&third, 1)
}))
g.AddPattern(NewPattern(25, func() {
atomic.AddUint32(&fourth, 1)
}))
// Run the generator
g.Execute()
// Assert
var lower uint32 = 2000
var upper uint32 = 3000
Ω(first).Should(BeNumerically(">=", lower))
Ω(first).Should(BeNumerically("<=", upper))
Ω(second).Should(BeNumerically(">=", lower))
Ω(second).Should(BeNumerically("<=", upper))
Ω(third).Should(BeNumerically(">=", lower))
Ω(third).Should(BeNumerically("<=", upper))
Ω(fourth).Should(BeNumerically(">=", lower))
Ω(fourth).Should(BeNumerically("<=", upper))
})
It("should be able to add 2 patterns with 25/75% prob", func() {
g := NewGenerator(1000, 1)
Ω(g).ShouldNot(BeNil())
var first, second uint32
g.AddPattern(NewPattern(25, func() {
atomic.AddUint32(&first, 1)
}))
g.AddPattern(NewPattern(75, func() {
atomic.AddUint32(&second, 1)
}))
g.Execute()
Ω(first).Should(BeNumerically(">=", uint32(200)))
Ω(first).Should(BeNumerically("<=", uint32(300)))
Ω(second).Should(BeNumerically(">=", uint32(700)))
Ω(second).Should(BeNumerically("<=", uint32(800)))
})
})