forked from WoSai/ultron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_test.go
49 lines (40 loc) · 1.03 KB
/
task_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
package ultron
import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func TestTask_PickUp(t *testing.T) {
task := NewTask()
task.Add(NewHTTPAttacker("task-1"), 5)
task.Add(NewHTTPAttacker("task-2"), 12)
task.PickUp()
actual := make(map[string]int)
for _, attacker := range task.preempted {
actual[attacker.Name()]++
}
assert.EqualValues(t, actual["task-1"], 5)
assert.EqualValues(t, actual["task-2"], 12)
}
func TestTask_PickUp2(t *testing.T) {
task := NewTask()
task.Add(NewHTTPAttacker("task-1"), 5)
task.Add(NewHTTPAttacker("task-2"), 12)
counter := make(map[string]uint32)
for i := 0; i < 1000*1000; i++ {
attacker := task.PickUp()
counter[attacker.Name()] += 1
}
Logger.Info("attacker picked up", zap.Any("attackers", counter))
}
func BenchmarkTest_PickUp(b *testing.B) {
task := NewTask()
task.Add(NewHTTPAttacker("task-1"), 5)
task.Add(NewHTTPAttacker("task-2"), 10)
task.Add(NewHTTPAttacker("task-3"), 20)
b.RunParallel(func(p *testing.PB) {
for p.Next() {
task.PickUp()
}
})
}