mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: add and expose StopSignal field in ExpectProcess
add and expose StopSignal to ExpectProcess allows user to define what signal to send on ExpectProcess.close() coverage testing code sets StopSignal to SIGTERM allowing the test binary to shutdown gracefully so that it can generate a coverage report.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/kr/pty"
|
||||
)
|
||||
@@ -38,6 +39,9 @@ type ExpectProcess struct {
|
||||
lines []string
|
||||
count int // increment whenever new line gets added
|
||||
err error
|
||||
|
||||
// StopSignal is the signal Stop sends to the process; defaults to SIGKILL.
|
||||
StopSignal os.Signal
|
||||
}
|
||||
|
||||
var printDebugLines = os.Getenv("EXPECT_DEBUG") != ""
|
||||
@@ -52,7 +56,10 @@ func NewExpect(name string, arg ...string) (ep *ExpectProcess, err error) {
|
||||
func NewExpectWithEnv(name string, args []string, env []string) (ep *ExpectProcess, err error) {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Env = env
|
||||
ep = &ExpectProcess{cmd: cmd}
|
||||
ep = &ExpectProcess{
|
||||
cmd: cmd,
|
||||
StopSignal: syscall.SIGKILL,
|
||||
}
|
||||
ep.cond = sync.NewCond(&ep.mu)
|
||||
ep.cmd.Stderr = ep.cmd.Stdout
|
||||
ep.cmd.Stdin = nil
|
||||
@@ -140,7 +147,7 @@ func (ep *ExpectProcess) close(kill bool) error {
|
||||
return ep.err
|
||||
}
|
||||
if kill {
|
||||
ep.Signal(os.Interrupt)
|
||||
ep.Signal(ep.StopSignal)
|
||||
}
|
||||
|
||||
err := ep.cmd.Wait()
|
||||
|
||||
Reference in New Issue
Block a user