forked from codeskyblue/gosuv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm_test.go
38 lines (34 loc) · 826 Bytes
/
fsm_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
package main
import (
"fmt"
"os/exec"
"strconv"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func findProcess(name string) bool {
name = fmt.Sprintf("[%c]%s", name[0], name[1:])
c := exec.Command("bash", "-c", fmt.Sprintf("ps -eo command | grep %s", strconv.Quote(name)))
output, err := c.CombinedOutput()
if err == nil {
So(string(output), ShouldNotEqual, "")
return true
}
return false
}
func TestStopCommand(t *testing.T) {
Convey("Stop command should clean up all program", t, func() {
p := NewProcess(Program{
Name: "sleep",
Command: "(echo hello; sleep 17&); exit 1",
StopTimeout: 1,
})
p.startCommand()
time.Sleep(100 * time.Millisecond)
p.stopCommand()
So(p.cmd, ShouldBeNil)
exists := findProcess("sleep 17")
So(exists, ShouldBeFalse)
})
}