packer/plugin: timeout when starting a plugin

This commit is contained in:
Mitchell Hashimoto 2013-05-07 19:39:20 -07:00
parent c9c294f136
commit 2ff1fabbf9
2 changed files with 9 additions and 0 deletions

View File

@ -25,18 +25,25 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
return
}
// Goroutine + channel to signal that the process exited
cmdExited := make(chan bool)
go func() {
cmd.Wait()
cmdExited <- true
}()
// Timer for a timeout
cmdTimeout := time.After(1 * time.Minute)
var address string
for done := false; !done; {
select {
case <-cmdExited:
err = errors.New("plugin exited before we could connect")
done = true
case <- cmdTimeout:
err = errors.New("timeout while waiting for plugin to start")
done = true
default:
}

View File

@ -6,6 +6,8 @@ import (
"testing"
)
// TODO: Test timeout functionality
func TestCommand_NoExist(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)