-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignal_test.go
62 lines (55 loc) · 1.23 KB
/
signal_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
package gutil
import (
"errors"
"github.com/stretchr/testify/assert"
"os"
"syscall"
"testing"
"time"
)
func TestWaitCallbackReturnNil(t *testing.T) {
callback := func(s os.Signal) error {
return nil
}
go func() {
time.Sleep(time.Second)
PanicErr(syscall.Kill(syscall.Getpid(), syscall.SIGINT))
}()
err := Wait(callback, syscall.SIGTERM, syscall.SIGINT)
assert.Nil(t, err)
}
func TestWaitCallbackReturnError(t *testing.T) {
myErr := errors.New("abc")
callback := func(s os.Signal) error {
return myErr
}
go func() {
time.Sleep(time.Second)
PanicErr(syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
}()
err := Wait(callback, syscall.SIGTERM)
assert.Equal(t, myErr, err)
}
func TestWaitUntilGetSignal(t *testing.T) {
callback := func(s os.Signal) error {
return nil
}
var slept = false
go func() {
time.Sleep(3 * time.Second)
slept = true
PanicErr(syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
}()
_ = Wait(callback, syscall.SIGTERM)
assert.True(t, slept)
}
func TestWaitForSignalGetSignal(t *testing.T) {
var slept = false
go func() {
time.Sleep(3 * time.Second)
slept = true
PanicErr(syscall.Kill(syscall.Getpid(), syscall.SIGTERM))
}()
WaitForSignals(syscall.SIGTERM)
assert.True(t, slept)
}