Beispiel #1
0
func StartRunnerAndMakeConnection(manifest *manifest.Manifest, writer execLogger.ExecutionLogger, killChannel chan bool) (*TestRunner, error) {
	port, err := conn.GetPortFromEnvironmentVariable(common.GaugePortEnvName)
	if err != nil {
		port = 0
	}
	gaugeConnectionHandler, connHandlerErr := conn.NewGaugeConnectionHandler(port, nil)
	if connHandlerErr != nil {
		return nil, connHandlerErr
	}
	testRunner, err := startRunner(manifest, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber()), writer, killChannel)
	if err != nil {
		return nil, err
	}

	runnerConnection, connectionError := gaugeConnectionHandler.AcceptConnection(config.RunnerConnectionTimeout(), testRunner.ErrorChannel)
	testRunner.Connection = runnerConnection
	if connectionError != nil {
		writer.Debug("Runner connection error: %s", connectionError)
		err := testRunner.killRunner()
		if err != nil {
			writer.Debug("Error while killing runner: %s", err)
		}
		return nil, connectionError
	}
	return testRunner, nil
}
Beispiel #2
0
func (testRunner *TestRunner) Kill(writer execLogger.ExecutionLogger) error {
	if testRunner.isStillRunning() {
		defer testRunner.Connection.Close()
		testRunner.sendProcessKillMessage()

		exited := make(chan bool, 1)
		go func() {
			for {
				if testRunner.isStillRunning() {
					time.Sleep(100 * time.Millisecond)
				} else {
					exited <- true
					return
				}
			}
		}()

		select {
		case done := <-exited:
			if done {
				return nil
			}
		case <-time.After(config.PluginKillTimeout()):
			writer.Warning("Killing runner with PID:%d forcefully\n", testRunner.Cmd.Process.Pid)
			return testRunner.killRunner()
		}
	}
	return nil
}
Beispiel #3
0
func waitAndGetErrorMessage(errChannel chan error, cmd *exec.Cmd, writer execLogger.ExecutionLogger) {
	go func() {
		err := cmd.Wait()
		if err != nil {
			writer.Debug("Runner exited with error: %s", err)
			errChannel <- errors.New(fmt.Sprintf("Runner exited with error: %s\n", err.Error()))
		}
	}()
}
Beispiel #4
0
func executeAndGetStatus(runner *runner.TestRunner, message *gauge_messages.Message, writer execLogger.ExecutionLogger) *gauge_messages.ProtoExecutionResult {
	response, err := conn.GetResponseForGaugeMessage(message, runner.Connection)
	if err != nil {
		return &gauge_messages.ProtoExecutionResult{Failed: proto.Bool(true), ErrorMessage: proto.String(err.Error())}
	}

	if response.GetMessageType() == gauge_messages.Message_ExecutionStatusResponse {
		executionResult := response.GetExecutionStatusResponse().GetExecutionResult()
		if executionResult == nil {
			errMsg := "ProtoExecutionResult obtained is nil"
			writer.Critical(errMsg)
			return errorResult(errMsg)
		}
		return executionResult
	} else {
		errMsg := fmt.Sprintf("Expected ExecutionStatusResponse. Obtained: %s", response.GetMessageType())
		writer.Critical(errMsg)
		return errorResult(errMsg)
	}
}
Beispiel #5
0
func printStatus(executionResult *gauge_messages.ProtoExecutionResult, writer execLogger.ExecutionLogger) {
	writer.PrintError(executionResult.GetErrorMessage())
	writer.PrintError(executionResult.GetStackTrace())
}