Skip to content

Commit

Permalink
Merge pull request intelsdi-x#1279 from geauxvirtual/tb/1230
Browse files Browse the repository at this point in the history
Fix intelsdi-x#1230: Return execute errors if plugin never starts
  • Loading branch information
IRCody authored Oct 12, 2016
2 parents 8328ec0 + 37fdcf2 commit e72f01e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions control/plugin/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ExecutablePlugin struct {
// An interface for the interactions ExecutablePlugin has with an exec.Cmd
// This way, the underlying Cmd can be mocked.
type command interface {
Start()
Start() error
Kill() error
Path() string
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (cw *commandWrapper) Kill() error {
_, err := cw.cmd.Process.Wait()
return err
}
func (cw *commandWrapper) Start() { cw.cmd.Start() }
func (cw *commandWrapper) Start() error { return cw.cmd.Start() }

// Initialize a new ExecutablePlugin from path to executable and daemon mode (true or false)
func NewExecutablePlugin(a Arg, path string) (*ExecutablePlugin, error) {
Expand Down Expand Up @@ -112,7 +112,10 @@ func (e *ExecutablePlugin) Run(timeout time.Duration) (Response, error) {
stdOutScanner := bufio.NewScanner(e.stdout)

// Start the command and begin reading its output.
e.cmd.Start()
if err = e.cmd.Start(); err != nil {
return resp, err
}

e.captureStderr()
go func() {
for {
Expand Down
2 changes: 1 addition & 1 deletion control/plugin/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type mockCmd struct{}

func (mc *mockCmd) Path() string { return "" }
func (mc *mockCmd) Kill() error { return nil }
func (mc *mockCmd) Start() {}
func (mc *mockCmd) Start() error { return nil }

func setupMockExec(resp []byte, timeout bool) *ExecutablePlugin {
stdout, stdoutw := io.Pipe()
Expand Down

0 comments on commit e72f01e

Please sign in to comment.