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
|
||||
}
|
||||
|
||||
// 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:
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// TODO: Test timeout functionality
|
||||
|
||||
func TestCommand_NoExist(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
|
|
Loading…
Reference in New Issue