mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/expect: support sending Signals to expect process
This commit is contained in:
parent
18992bac4f
commit
fcb5ba98d0
@ -113,6 +113,11 @@ func (ep *ExpectProcess) LineCount() int {
|
||||
// Stop kills the expect process and waits for it to exit.
|
||||
func (ep *ExpectProcess) Stop() error { return ep.close(true) }
|
||||
|
||||
// Signal sends a signal to the expect process
|
||||
func (ep *ExpectProcess) Signal(sig os.Signal) error {
|
||||
return ep.cmd.Process.Signal(sig)
|
||||
}
|
||||
|
||||
// Close waits for the expect process to exit.
|
||||
func (ep *ExpectProcess) Close() error { return ep.close(false) }
|
||||
|
||||
|
@ -16,7 +16,11 @@
|
||||
|
||||
package expect
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestExpectFunc(t *testing.T) {
|
||||
ep, err := NewExpect("/bin/echo", "hello world")
|
||||
@ -93,3 +97,24 @@ func TestSend(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignal(t *testing.T) {
|
||||
ep, err := NewExpect("/bin/sleep", "100")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ep.Signal(os.Interrupt)
|
||||
donec := make(chan struct{})
|
||||
go func() {
|
||||
defer close(donec)
|
||||
werr := "signal: interrupt"
|
||||
if cerr := ep.Close(); cerr == nil || cerr.Error() != werr {
|
||||
t.Fatalf("got error %v, wanted error %s", cerr, werr)
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("signal test timed out")
|
||||
case <-donec:
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user