-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_norace_test.go
82 lines (67 loc) · 1.63 KB
/
main_norace_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
//go:build !race
// +build !race
package main
import (
"bytes"
"fmt"
"log"
"os"
"strings"
"syscall"
"testing"
"time"
)
func assertSignal(s os.Signal) error {
memLog := bytes.Buffer{}
log.SetOutput(&memLog)
defer log.SetOutput(os.Stderr) // os.Stderr is the default output
expectedPrint := lobbySettings.outro
wt := 2
var lbs []*lb
signalHandler(s, sSig, &lbs)
time.Sleep(time.Duration(wt) * time.Second)
if !strings.Contains(memLog.String(), expectedPrint) {
return fmt.Errorf("%s log level assertion failed", expectedPrint)
}
return nil
}
func TestSIGINT(t *testing.T) {
config := `lb:
`
testConfigPath := "/tmp/lobby_test_conf.yaml"
lobbySettings.configFilePath = testConfigPath
os.WriteFile(testConfigPath, []byte(config), 0400)
go main()
wt := 2
time.Sleep(time.Duration(wt) * time.Second)
os.Remove(testConfigPath)
if err := assertSignal(syscall.SIGINT); err != nil {
t.Errorf("Signal result assertion failed: %v", err)
}
}
func TestSIGTERM(t *testing.T) {
config := `lb:
- engine: testEngine
targets:
- name: testReconfig
protocol: tcp
port: 8082
upstream_group:
name: ug
distribution: round-robin
upstreams:
- name: testUpstream
host: 1.1.1.1
port: 80
`
testConfigPath := "/tmp/lobby_test_conf.yaml"
lobbySettings.configFilePath = testConfigPath
os.WriteFile(testConfigPath, []byte(config), 0400)
go main()
wt := 2
time.Sleep(time.Duration(wt) * time.Second)
os.Remove(testConfigPath)
if err := assertSignal(syscall.SIGTERM); err != nil {
t.Errorf("Signal result assertion failed: %v", err)
}
}