forked from vrecan/death
/
death_unix_test.go
56 lines (43 loc) · 1.03 KB
/
death_unix_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
// +build linux bsd darwin
package death
import (
log "github.com/cihub/seelog"
. "github.com/smartystreets/goconvey/convey"
"os"
"syscall"
"testing"
"time"
)
func TestDeath(t *testing.T) {
defer log.Flush()
Convey("Validate death happens cleanly", t, func() {
death := NewDeath(syscall.SIGTERM)
syscall.Kill(os.Getpid(), syscall.SIGTERM)
death.WaitForDeath()
})
Convey("Validate death happens with other signals", t, func() {
death := NewDeath(syscall.SIGHUP)
closeMe := &CloseMe{}
syscall.Kill(os.Getpid(), syscall.SIGHUP)
death.WaitForDeath(closeMe)
So(closeMe.Closed, ShouldEqual, 1)
})
Convey("Validate death gives up after timeout", t, func() {
death := NewDeath(syscall.SIGHUP)
death.setTimeout(10 * time.Millisecond)
neverClose := &neverClose{}
syscall.Kill(os.Getpid(), syscall.SIGHUP)
death.WaitForDeath(neverClose)
})
}
type neverClose struct {
}
func (n *neverClose) Close() {
time.Sleep(2 * time.Minute)
}
type CloseMe struct {
Closed int
}
func (c *CloseMe) Close() {
c.Closed++
}