forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocust.go
58 lines (47 loc) · 923 Bytes
/
locust.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
package glocust
// Define locust interface.
type Locust interface {
Min() int
Max() int
Tasks() []Task
WeightsTasks() []Task
OnStart()
CatchExceptions() bool
}
type Task struct {
Weight int
Fn func()
}
type LocustMate struct {
MinWait int
MaxWait int
TaskSet []Task
Catchexceptions bool
}
func (l *LocustMate) Min() int {
return l.MinWait
}
func (l *LocustMate) Max() int {
return l.MaxWait
}
func (l *LocustMate) Tasks() []Task {
return l.TaskSet
}
func (l *LocustMate) OnStart() {
}
func (l *LocustMate) AddTask(weight int, fn func()) {
task := Task{Weight: weight, Fn: fn}
l.TaskSet = append(l.TaskSet, task)
}
func (l *LocustMate) CatchExceptions() bool {
return l.Catchexceptions
}
func (l *LocustMate) WeightsTasks() []Task {
var tasks []Task
for _, v := range l.TaskSet {
for i := 0; i < v.Weight; i++ {
tasks = append(tasks, v)
}
}
return tasks
}