1 Star 0 Fork 34

maxid/distributed-gosuv

forked from haiker/sudis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fsm_test.go 826 Bytes
一键复制 编辑 原始数据 按行查看 历史
haiker 提交于 2017-12-03 19:46 . 分布式实现
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)
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/istyle/distributed-gosuv.git
git@gitee.com:istyle/distributed-gosuv.git
istyle
distributed-gosuv
distributed-gosuv
master

搜索帮助