-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (66 loc) · 1.38 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
package main
import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"
)
var version = "dev"
func main() {
go testLoop()
go func() {
reload := make(chan os.Signal, 1)
signal.Notify(reload, syscall.SIGHUP)
for range reload {
fmt.Println("Received SIGHUP: reloading config")
config.Store(loadConfig())
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT)
signal.Notify(quit, syscall.SIGTERM)
<-quit
}
func testLoop() {
i := 0
for {
c := getConfig()
offset := float64(15) / float64(len(c.tests))
duration := time.Duration(offset * float64(time.Second))
if i >= len(c.tests) {
i = 0
}
go func(t *Test) {
err := t.Run()
if err != nil {
if strings.Contains(err.Error(), "Client.Timeout") {
err = fmt.Errorf("response time was greater than %d milliseconds", t.MaxResponseTime)
}
errStr := fmt.Sprintf("Test failed: %s: %s", t.Name, err)
if version == "dev" {
fmt.Println(errStr)
}
if t.ShouldNotify() && !t.notified {
err := notify(errStr)
if err != nil {
fmt.Println("error sending Slack notification:", err)
} else {
t.notified = true
}
}
} else {
if version == "dev" {
fmt.Println("Test success:", t.Name)
}
if t.notified {
notifyf("Test recovered: %s", t.Name)
}
t.notified = false
}
}(c.tests[i])
time.Sleep(duration)
i++
}
}