forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (62 loc) · 1.57 KB
/
main.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
package main
import (
"log"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/naturezhm/boomer"
)
func foo() {
start := time.Now()
time.Sleep(100 * time.Millisecond)
elapsed := time.Since(start)
// Report your test result as a success, if you write it in python, it will looks like this
// events.request_success.fire(request_type="http", name="foo", response_time=100, response_length=10)
globalBoomer.RecordSuccess("http", "foo", elapsed.Nanoseconds()/int64(time.Millisecond), int64(10))
}
func bar() {
start := time.Now()
time.Sleep(100 * time.Millisecond)
elapsed := time.Since(start)
// Report your test result as a failure, if you write it in python, it will looks like this
// events.request_failure.fire(request_type="udp", name="bar", response_time=100, exception=Exception("udp error"))
globalBoomer.RecordFailure("udp", "bar", elapsed.Nanoseconds()/int64(time.Millisecond), "udp error")
}
func waitForQuit() {
wg := sync.WaitGroup{}
wg.Add(1)
quitByMe := false
go func() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
quitByMe = true
globalBoomer.Quit()
wg.Done()
}()
boomer.Events.Subscribe("boomer:quit", func() {
if !quitByMe {
wg.Done()
}
})
wg.Wait()
}
var globalBoomer = boomer.NewBoomer("127.0.0.1", 5557)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
task1 := &boomer.Task{
Name: "foo",
Weight: 10,
Fn: foo,
}
task2 := &boomer.Task{
Name: "bar",
Weight: 30,
Fn: bar,
}
globalBoomer.Run(task1, task2)
waitForQuit()
log.Println("shut down")
}