packer/plugin: timeout when starting a plugin
This commit is contained in:
parent
c9c294f136
commit
2ff1fabbf9
|
@ -25,18 +25,25 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Goroutine + channel to signal that the process exited
|
||||||
cmdExited := make(chan bool)
|
cmdExited := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
cmdExited <- true
|
cmdExited <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Timer for a timeout
|
||||||
|
cmdTimeout := time.After(1 * time.Minute)
|
||||||
|
|
||||||
var address string
|
var address string
|
||||||
for done := false; !done; {
|
for done := false; !done; {
|
||||||
select {
|
select {
|
||||||
case <-cmdExited:
|
case <-cmdExited:
|
||||||
err = errors.New("plugin exited before we could connect")
|
err = errors.New("plugin exited before we could connect")
|
||||||
done = true
|
done = true
|
||||||
|
case <- cmdTimeout:
|
||||||
|
err = errors.New("timeout while waiting for plugin to start")
|
||||||
|
done = true
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Test timeout functionality
|
||||||
|
|
||||||
func TestCommand_NoExist(t *testing.T) {
|
func TestCommand_NoExist(t *testing.T) {
|
||||||
assert := asserts.NewTestingAsserts(t, true)
|
assert := asserts.NewTestingAsserts(t, true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue