-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreaker_data_2_test.go
87 lines (78 loc) · 1.96 KB
/
breaker_data_2_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
package breaker
import (
"fmt"
"math/rand"
"time"
"github.com/sirupsen/logrus"
)
type wrapperE1 struct {
state string
}
func (w *wrapperE1) CommandFunc() {
time.Sleep(100 * time.Millisecond)
fmt.Println("Executing ", w.state)
}
func (w *wrapperE1) DefaultFunc() {
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Defaulted": w.state}).Info("task was defaulted")
//fmt.Println("Defaulting command.....")
}
func (w *wrapperE1) CleanupFunc() {
log.WithFields(logrus.Fields{"Cleaned": w.state}).Info("task was cleaned")
//fmt.Println("Canceling command.....")
}
func (w *wrapperE1) timeout() time.Duration {
return 200 * time.Millisecond
}
func (w *wrapperE1) Name() string {
return "task1"
}
type wrapperE2 struct {
state string
}
func (w *wrapperE2) CommandFunc() {
time.Sleep(100 * time.Millisecond)
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Executed": w.state}).Info("task was executed")
}
func (w *wrapperE2) DefaultFunc() {
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Defaulted": w.state}).Info("task was defaulted")
}
func (w *wrapperE2) CleanupFunc() {
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Cleaned": w.state}).Info("task was cleaned")
}
func (w *wrapperE2) timeout() time.Duration {
return 50 * time.Millisecond
}
func (w *wrapperE2) Name() string {
return "task1"
}
type wrapperE3 struct {
state string
done bool
}
func (w *wrapperE3) CommandFunc() {
for i := 1; i < 100; i++ {
time.Sleep(1 * time.Millisecond)
if w.done {
return
}
}
log.Formatter = new(logrus.JSONFormatter)
log.WithFields(logrus.Fields{"Executed": w.state}).Info("task was executed")
}
func (w *wrapperE3) DefaultFunc() {
fmt.Println("Calling done")
w.done = true
}
func (w *wrapperE3) CleanupFunc() {
}
func randMillis(i int64) time.Duration {
r := rand.Int63n(i)
return time.Duration(r) * time.Millisecond
}
func (w *wrapperE3) Name() string {
return "task1"
}