-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
a_test.go
68 lines (58 loc) · 1.15 KB
/
a_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
package immortal
import (
// "fmt"
"os"
"reflect"
"syscall"
"testing"
)
/* Test Helpers */
func expect(t *testing.T, a interface{}, b interface{}, where ...string) {
var w string
if len(where) > 0 {
w = where[0]
}
if a != b {
t.Fatalf("Expected: %v (type %v) Got: %v (type %v) %v", a, reflect.TypeOf(a), b, reflect.TypeOf(b), w)
}
}
type myFork struct{}
func (self myFork) Fork() (int, error) {
return 0, nil
}
type catchSignals struct {
*os.Process
signal chan os.Signal
wait chan struct{}
}
func (self *catchSignals) GetPid() int {
return self.Pid
}
func (self *catchSignals) SetPid(pid int) {
self.Pid = pid
}
func (self *catchSignals) SetProcess(p *os.Process) {
self.Process = p
self.wait <- struct{}{}
}
func (self *catchSignals) Kill() (err error) {
err = self.Process.Kill()
if err != nil {
return
}
// to avoid zombie
_, err = self.Process.Wait()
if err != nil {
return
}
return
}
func (self *catchSignals) Signal(sig os.Signal) error {
process, _ := os.FindProcess(self.Pid)
if err := process.Signal(syscall.Signal(0)); err != nil {
self.signal <- syscall.SIGILL
return err
}
self.signal <- sig
return nil
}