Commit bbc5f305 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: RemoteCmd.Wait

parent fdda64f4
......@@ -2,6 +2,7 @@ package packer
import (
"io"
"time"
)
// RemoteCmd represents a remote command being prepared or run.
......@@ -42,3 +43,10 @@ type Communicator interface {
Upload(string, io.Reader) error
Download(string, io.Writer) error
}
// Wait waits for the remote command to complete.
func (r *RemoteCmd) Wait() {
for !r.Exited {
time.Sleep(50 * time.Millisecond)
}
}
package packer
import (
"testing"
"time"
)
func TestRemoteCmd_Wait(t *testing.T) {
var cmd RemoteCmd
result := make(chan bool)
go func() {
cmd.Wait()
result <- true
}()
cmd.ExitStatus = 42
cmd.Exited = true
select {
case <-result:
// Success
case <-time.After(500 * time.Millisecond):
t.Fatal("never got exit notification")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment