private void FillFinalExceptionReportInfo(Exception ex, out StatusReportType finalReportType,
                                                  out StepResult lastStepResult, out FailedInfo failedInfo)
        {
            if (ex is TaskFailedException)
            {
                TaskFailedException failedException = (TaskFailedException)ex;
                FailedType          failedType      = failedException.FailedType;
                this.State      = ModuleUtils.GetRuntimeState(failedType);
                finalReportType = ModuleUtils.GetReportType(failedType);
                lastStepResult  = ModuleUtils.GetStepResult(failedType);
                failedInfo      = new FailedInfo(ex, failedType);
                _context.LogSession.Print(LogLevel.Info, Index, "Step force failed.");
            }
            else if (ex is TestflowAssertException)
            {
                this.State      = RuntimeState.Failed;
                finalReportType = StatusReportType.Failed;
                lastStepResult  = StepResult.Failed;
                failedInfo      = new FailedInfo(ex, FailedType.AssertionFailed);
                _context.LogSession.Print(LogLevel.Error, Index, "Assert exception catched.");
            }
            else if (ex is ThreadAbortException)
            {
                this.State      = RuntimeState.Abort;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Abort;
                failedInfo      = new FailedInfo(ex, FailedType.Abort);
                _context.LogSession.Print(LogLevel.Warn, Index, $"Sequence {Index} execution aborted");
            }
            else if (ex is TestflowException)
            {
                this.State      = RuntimeState.Error;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Error;
                failedInfo      = new FailedInfo(ex, FailedType.RuntimeError);
                _context.LogSession.Print(LogLevel.Error, Index, ex, "Inner exception catched.");
            }
            else
            {
                this.State      = RuntimeState.Error;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Error;
                failedInfo      = new FailedInfo(ex, FailedType.RuntimeError);
                _context.LogSession.Print(LogLevel.Error, Index, ex, "Runtime exception catched.");
            }
//            else if (ex is TargetInvocationException)
//            {
//                this.State = RuntimeState.Failed;
//                finalReportType = StatusReportType.Failed;
//                lastStepResult = StepResult.Failed;
//                failedInfo = new FailedInfo(ex.InnerException, FailedType.TargetError);
//                _context.LogSession.Print(LogLevel.Error, Index, ex, "Invocation exception catched.");
//            }
        }
        bool RetryExceptionHandler(Exception e)
        {
            TaskFailedException tfe = e as TaskFailedException;

            if (tfe != null && tfe.InnerException != null)
            {
                e = tfe.InnerException;
            }

            CounterException ce = e as CounterException;

            if (ce != null)
            {
                LatestException = ce;
                return(true);
            }

            return(false);
        }
        public void HandleTaskFailedEvent(TaskFailedEvent failedEvent)
        {
            int taskId = failedEvent.TaskScheduledId;

            if (openTasks.ContainsKey(taskId))
            {
                OpenTaskInfo info  = openTasks[taskId];
                Exception    cause = Utils.RetrieveCause(failedEvent.Details, dataConverter);

                var taskFailedException = new TaskFailedException(failedEvent.EventId, taskId, info.Name, info.Version,
                                                                  failedEvent.Reason, cause);

                TaskCompletionSource <string> tcs = info.Result;
                tcs.SetException(taskFailedException);

                openTasks.Remove(taskId);
            }
            else
            {
                LogDuplicateEvent("TaskFailed", failedEvent, taskId);
            }
        }
        public void HandleTaskFailedEvent(TaskFailedEvent failedEvent)
        {
            int taskId = failedEvent.TaskScheduledId;

            if (this.openTasks.ContainsKey(taskId))
            {
                OpenTaskInfo info = this.openTasks[taskId];

                // When using ErrorPropagationMode.SerializeExceptions the "cause" is deserialized from history.
                // This isn't fully reliable because not all exception types can be serialized/deserialized.
                // When using ErrorPropagationMode.UseFailureDetails we instead use FailureDetails to convey
                // error information, which doesn't involve any serialization at all.
                Exception cause = this.ErrorPropagationMode == ErrorPropagationMode.SerializeExceptions ?
                                  Utils.RetrieveCause(failedEvent.Details, this.ErrorDataConverter) :
                                  null;

                var taskFailedException = new TaskFailedException(
                    failedEvent.EventId,
                    taskId,
                    info.Name,
                    info.Version,
                    failedEvent.Reason,
                    cause);

                taskFailedException.FailureDetails = failedEvent.FailureDetails;

                TaskCompletionSource <string> tcs = info.Result;
                tcs.SetException(taskFailedException);

                this.openTasks.Remove(taskId);
            }
            else
            {
                LogDuplicateEvent("TaskFailed", failedEvent, taskId);
            }
        }
        public override void Read(ChannelHandlerContext ctx, object msg)
        {
            // Java uses a SimpleChannelInboundHandler that only expects Message objects
            var responseMessage = msg as Message.Message;

            if (responseMessage == null)
            {
                return;
            }

            if (responseMessage.Command == Rpc.Rpc.Commands.Rcon.GetNr() &&
                responseMessage.Type == Message.Message.MessageType.Ok)
            {
                Logger.Debug("Successfully set up the reverse connection to peer {0}.", responseMessage.Recipient.PeerId);
                _tcsRconResponse.SetResult(responseMessage);
            }
            else
            {
                Logger.Debug("Could not acquire a reverse connection to peer {0}.", responseMessage.Recipient.PeerId);
                var ex = new TaskFailedException("Could not acquire a reverse connection. Got: " + responseMessage);
                _tcsRconResponse.SetException(ex);
                _tcsResponse.SetException(ex);
            }
        }
Exemple #6
0
        // 使能retry调用step
        private void InvokeStepWithRetry(bool forceInvoke)
        {
            int    maxRetry     = StepData.RetryCounter.MaxRetryTimes;
            int    passTimes    = StepData.RetryCounter.PassTimes;
            string retryVar     = null;
            string passCountVar = null;

            if (CoreUtils.IsValidVaraible(StepData.RetryCounter.CounterVariable))
            {
                retryVar = ModuleUtils.GetVariableFullName(StepData.RetryCounter.CounterVariable, StepData,
                                                           Context.SessionId);
            }
            if (CoreUtils.IsValidVaraible(StepData.RetryCounter.PassCountVariable))
            {
                passCountVar = ModuleUtils.GetVariableFullName(StepData.RetryCounter.PassCountVariable, StepData,
                                                               Context.SessionId);
            }
            int retryTimes = 0;
            int passCount  = 0;
            TestflowLoopBreakException loopBreakException = null;

            while (retryTimes < maxRetry && passCount < passTimes)
            {
                retryTimes++;
                if (null != retryVar)
                {
                    Context.VariableMapper.SetParamValue(retryVar, StepData.RetryCounter.CounterVariable, retryTimes);
                }
                try
                {
                    InvokeStepSingleTime(forceInvoke);
                    // 如果当前节点和所有子节点都执行成功,则成功计数加一
                    if (!ModuleUtils.IsStepFailed(this.Result) && ModuleUtils.IsSubStepPassed(SubStepRoot))
                    {
                        passCount++;
                    }
                    if (null != passCountVar)
                    {
                        Context.VariableMapper.SetParamValue(passCountVar, StepData.RetryCounter.PassCountVariable,
                                                             passCount);
                    }
                }
                catch (TaskFailedException ex)
                {
                    // 如果该失败类型不能被处理,则直接向上抛出
                    if (!ModuleUtils.IsErrorCanBeHandled(ex.FailedType))
                    {
                        throw;
                    }
                    // 停止计时
                    Actuator.EndTiming();
                    this.Result = StepResult.RetryFailed;
                    RecordInvocationError(ex, ex.FailedType);
                }
                catch (TestflowAssertException ex)
                {
                    // 停止计时
                    Actuator.EndTiming();
                    this.Result = StepResult.RetryFailed;
                    RecordInvocationError(ex, FailedType.AssertionFailed);
                }
                catch (TestflowLoopBreakException ex)
                {
                    // 该异常已经在内部处理
                    loopBreakException = ex;
                }
                catch (TargetInvocationException ex)
                {
                    // 停止计时
                    Actuator.EndTiming();
                    RecordRetryTargetInvocationError(ex);
                }
                catch (TargetException ex)
                {
                    // 停止计时
                    Actuator.EndTiming();
                    RecordInvocationError(ex, FailedType.TargetError);
                }
            }
            // 如果成功次数小于预订的成功次数,则抛出异常
            if (passCount < passTimes)
            {
                TaskFailedException retryFailedException = new TaskFailedException(SequenceIndex,
                                                                                   Context.I18N.GetStr("MaxRetryFailed"), FailedType.RetryFailed);
                this.Result = StepResult.Failed;
                RecordInvocationError(retryFailedException, retryFailedException.FailedType);
                // 如果期间未发生LoopBreakException,则直接抛出FailedException
                if (null == loopBreakException)
                {
                    throw retryFailedException;
                }
                else
                {
                    // 如果期间发生LoopBreakException,则直接抛出以备上层处理流程更新
                    throw loopBreakException;
                }
            }
            else
            {
                this.Result = StepResult.Pass;
            }
        }