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:
parent
b5be18a744
commit
07129a6370
@ -19,10 +19,10 @@ package e2e
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/pkg/expect"
|
||||
"github.com/coreos/etcd/pkg/fileutil"
|
||||
@ -44,7 +44,13 @@ func spawnCmd(args []string) (*expect.ExpectProcess, error) {
|
||||
fmt.Sprintf("-test.coverprofile=e2e.%v.coverprofile", time.Now().UnixNano()),
|
||||
"-test.outputdir=" + coverPath,
|
||||
}
|
||||
return expect.NewExpectWithEnv(binDir+"/etcd_test", covArgs, args2env(args[1:]))
|
||||
ep := expect.NewExpectWithEnv(binDir+"/etcd_test", covArgs, args2env(args[1:]))
|
||||
// ep sends SIGTERM to etcd_test process on ep.close()
|
||||
// allowing the process to exit gracefully in order to generate a coverage report.
|
||||
// note: go runtime ignores SIGINT but not SIGTERM
|
||||
// if e2e test is run as a background process.
|
||||
ep.StopSignal = syscall.SIGTERM
|
||||
return nil, ep
|
||||
}
|
||||
return expect.NewExpect(args[0], args[1:]...)
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user