Exemple #1
0
        protected override void InvokeStepSingleTime(bool forceInvoke)
        {
            // 重置计时时间
            Actuator.ResetTiming();
            // 调用前置监听
            OnPreListener();

            this.Result = StepResult.NotAvailable;
            this.Result = Actuator.InvokeStep(forceInvoke);
            // 如果当前step被标记为记录状态,则返回状态信息
            if (null != StepData && StepData.RecordStatus)
            {
                RecordRuntimeStatus();
            }
            // 调用后置监听
            OnPostListener();

            if (null != StepData && StepData.HasSubSteps)
            {
                StepTaskEntityBase subStepEntity = SubStepRoot;
                do
                {
                    if (!forceInvoke && Context.Cancellation.IsCancellationRequested)
                    {
                        this.Result = StepResult.Abort;
                        return;
                    }
                    subStepEntity.Invoke(forceInvoke);
                } while (null != (subStepEntity = subStepEntity.NextStep));
            }
        }
        public StepTaskEntityBase GetStepEntity(ICallStack stack)
        {
            // 当前当前StepRoot为null,则说明序列已经执行结束,返回null
            if (null == _stepEntityRoot)
            {
                return(null);
            }
            StepTaskEntityBase currentStep = _stepEntityRoot;
            int currentLevel = 0;
            int stepId       = stack.StepStack[currentLevel];

            for (int i = 0; i < stepId; i++)
            {
                currentStep = currentStep.NextStep;
            }
            currentLevel++;
            while (currentLevel < stack.StepStack.Count && null != currentStep.SubStepRoot)
            {
                currentStep = currentStep.SubStepRoot;
                stepId      = stack.StepStack[currentLevel];
                for (int i = 0; i < stepId; i++)
                {
                    currentStep = currentStep.NextStep;
                }
                currentLevel++;
            }
            return(currentStep);
        }
        protected override void InvokeStepSingleTime(bool forceInvoke)
        {
            // 重置计时
            Actuator.ResetTiming();
            // 调用前置监听
            OnPreListener();

            // 开始计时
            Actuator.StartTiming();
            // 停止计时
            Actuator.EndTiming();
            // 应为TryFinally块上级为空,默认为pass
            this.Result = StepResult.Pass;
            // 调用后置监听
            OnPostListener();

            StepTaskEntityBase tryBlock     = SubStepRoot;
            StepTaskEntityBase finallyBlock = tryBlock.NextStep;

            try
            {
                tryBlock.Invoke(forceInvoke);
            }
            finally
            {
                // finally模块是强制调用
                finallyBlock.Invoke(true);
            }
            if (null != StepData && StepData.RecordStatus)
            {
                RecordRuntimeStatus();
            }
        }
        private void SetResultState(out StepResult lastStepResult, out StatusReportType finalReportType,
                                    out FailedInfo failedInfo)
        {
            StepTaskEntityBase lastStep = StepTaskEntityBase.GetCurrentStep(this.Index, RootCoroutineId);

            lastStepResult = lastStep.Result;
            failedInfo     = null;
            this.State     = ModuleUtils.GetSequenceState(this._stepEntityRoot);
            switch (this.State)
            {
            case RuntimeState.Over:
            case RuntimeState.Success:
                finalReportType = StatusReportType.Over;
                break;

            case RuntimeState.Failed:
                finalReportType = StatusReportType.Failed;
                break;

            case RuntimeState.Timeout:
            case RuntimeState.Error:
                finalReportType = StatusReportType.Error;
                break;

            case RuntimeState.Abort:
                finalReportType = StatusReportType.Error;
                failedInfo      = new FailedInfo("Sequence aborted", FailedType.Abort);
                _context.LogSession.Print(LogLevel.Warn, Index, $"Sequence {Index} execution aborted");
                break;

            default:
                finalReportType = StatusReportType.Over;
                break;
            }
        }
Exemple #5
0
 public static void AddSequenceEntrance(StepTaskEntityBase stepModel)
 {
     if (!CurrentModel.ContainsKey(stepModel.SequenceIndex))
     {
         CurrentModel.Add(stepModel.SequenceIndex,
                          new Dictionary <int, StepTaskEntityBase>(Constants.DefaultRuntimeSize));
     }
     CurrentModel[stepModel.SequenceIndex].Add(stepModel.Coroutine.Id, stepModel);
 }
 public void FillStatusInfo(StatusMessage message, string errorInfo)
 {
     // 如果是外部调用且该序列已经执行结束或者message中已经有了当前序列的信息,则说明该序列在前面的消息中已经标记结束,直接返回。
     if (message.InterestedSequence.Contains(this.Index) || this.State > RuntimeState.AbortRequested)
     {
         return;
     }
     message.Stacks.Add(StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId).GetStack());
     message.SequenceStates.Add(this.State);
     message.Results.Add(StepResult.NotAvailable);
 }
        public void FillStatusInfo(StatusMessage message)
        {
            // 如果是外部调用且该序列已经执行结束或者未开始或者message中已经有了当前序列的信息,则说明该序列在前面的消息中已经标记结束,直接返回。
            if (message.InterestedSequence.Contains(this.Index) || this.State > RuntimeState.AbortRequested || this.State == RuntimeState.StartIdle)
            {
                return;
            }
            message.SequenceStates.Add(this.State);
            StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);

            currentStep.FillStatusInfo(message);
        }
Exemple #8
0
 protected StepTaskEntityBase(ISequenceStep step, SlaveContext context, int sequenceIndex)
 {
     this.Context       = context;
     this.StepData      = step;
     this.Result        = StepResult.NotAvailable;
     this.SequenceIndex = sequenceIndex;
     this.Actuator      = ActuatorBase.GetActuator(step, context, sequenceIndex);
     this.Coroutine     = null;
     // 只有在断言失败和调用异常都配置为终止执行时,该步骤才会被判断为失败后终止
     if (null != StepData && StepData.HasSubSteps)
     {
         this.SubStepRoot = ModuleUtils.CreateSubStepModelChain(StepData.SubSteps, Context, sequenceIndex);
     }
     BreakIfFailed = (null == StepData) || (StepData.AssertFailedAction == FailedAction.Terminate &&
                                            StepData.InvokeErrorAction == FailedAction.Terminate);
 }
Exemple #9
0
 public virtual void Generate(ref int coroutineId)
 {
     this.Coroutine = Context.CoroutineManager.GetCoroutineHandle(coroutineId);
     Actuator.Generate(coroutineId);
     // 只有在StepData的LoopCounter不为null,loop最大值大于1,并且Step类型不是ConditionLoop的情况下才会执行LoopCounter
     this._hasLoopCounter = (StepData?.LoopCounter != null && StepData.LoopCounter.MaxValue > 1 &&
                             StepData.StepType != SequenceStepType.ConditionLoop);
     this._isUnderRetryStep = IsUnderRetryBlock();
     if (StepData?.HasSubSteps ?? false)
     {
         StepTaskEntityBase subStepEntity = SubStepRoot;
         do
         {
             subStepEntity.Generate(ref coroutineId);
         } while (null != (subStepEntity = subStepEntity.NextStep));
     }
     InintializeInvokeAction();
 }
        public void Generate(int startCoroutineId)
        {
            this.RootCoroutineId = startCoroutineId;
            this.State           = RuntimeState.TestGen;
            _stepEntityRoot      = ModuleUtils.CreateStepModelChain(_sequence.Steps, _context, _sequence.Index);
            if (null == _stepEntityRoot)
            {
                return;
            }

            StepTaskEntityBase stepEntity = _stepEntityRoot;

            do
            {
                stepEntity.Generate(ref startCoroutineId);
            } while (null != (stepEntity = stepEntity.NextStep));

            this.State = RuntimeState.StartIdle;
            // 添加当前根节点到stepModel管理中
            StepTaskEntityBase.AddSequenceEntrance(_stepEntityRoot);
        }
        protected override void InvokeStepSingleTime(bool forceInvoke)
        {
            // 重置计时时间
            Actuator.ResetTiming();
            // 调用前置监听
            OnPreListener();
            this.Result = StepResult.NotAvailable;
            this.Result = Actuator.InvokeStep(forceInvoke);

            // 如果当前step被标记为记录状态,则返回状态信息
            if (null != StepData && StepData.RecordStatus)
            {
                RecordRuntimeStatus();
            }
            // 调用后置监听
            OnPostListener();
            object returnValue = Actuator.Return;
            // 如果执行结果不是bool类型或者为False,或者没有下级节点,则退出当前循环
            bool conditionFail = !(returnValue is bool) || !(bool)returnValue;

            if (conditionFail || null == StepData || !StepData.HasSubSteps)
            {
                return;
            }
            // 执行下级的所有Step
            StepTaskEntityBase subStepEntity = SubStepRoot;

            do
            {
                if (!forceInvoke && Context.Cancellation.IsCancellationRequested)
                {
                    this.Result = StepResult.Abort;
                    return;
                }
                subStepEntity.Invoke(forceInvoke);
            } while (null != (subStepEntity = subStepEntity.NextStep));
        }
//        protected override void CheckSequenceData()
//        {
//            if (null != StepData.Function)
//            {
//                Context.LogSession.Print(LogLevel.Error, Context.SessionId,
//                    $"Conditionblock cannot configure function data. Step:{StepData.Name}");
//                I18N i18N = I18N.GetInstance(Constants.I18nName);
//                throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetStr("ConditionBlockHasFunc"));
//
//            }
//            if (null != StepData.SubSteps &&
//                StepData.SubSteps.Any(item => item.StepType != SequenceStepType.ConditionStatement))
//            {
//                Context.LogSession.Print(LogLevel.Error, Context.SessionId,
//                    $"Some steps under condition block is not ConditionStatement type. Step:{GetStack()}");
//                I18N i18N = I18N.GetInstance(Constants.I18nName);
//                throw new TestflowDataException(ModuleErrorCode.SequenceDataError, i18N.GetStr("IllegalStepType"));
//            }
//        }

        protected override void InvokeStepSingleTime(bool forceInvoke)
        {
            // 重置计时时间
            Actuator.ResetTiming();

            // 调用前置监听
            OnPreListener();

            // 开始计时
            Actuator.StartTiming();
            // 停止计时
            Actuator.EndTiming();
            this.Result = StepResult.Pass;
            // 如果当前step被标记为记录状态,则返回状态信息
            if (null != StepData && StepData.RecordStatus)
            {
                RecordRuntimeStatus();
            }

            // 调用后置监听
            OnPostListener();

            if (null != StepData && StepData.HasSubSteps)
            {
                StepTaskEntityBase subStepEntity = SubStepRoot;
                do
                {
                    subStepEntity.Invoke(forceInvoke);
                    object returnValue = subStepEntity.Return;
                    // 如果ConditionStatement返回值为True则说明该分支已执行完成,则跳过后续的Step
                    if (returnValue is bool && (bool)returnValue)
                    {
                        break;
                    }
                } while (null != (subStepEntity = subStepEntity.NextStep));
            }
        }
Exemple #13
0
        protected override void InvokeStepSingleTime(bool forceInvoke)
        {
            int index = 0;

            while (true)
            {
                try
                {
                    while (true)
                    {
                        // 设置循环变量的值
                        if (null != _loopVariable)
                        {
                            Context.VariableMapper.SetParamValue(_loopVariable, StepData.LoopCounter.CounterVariable,
                                                                 index++);
                        }
                        // 如果是取消状态并且不是强制执行则返回。因为ConditionLoop内部有循环,所以需要在内部也做判断
                        if (!forceInvoke && Context.Cancellation.IsCancellationRequested)
                        {
                            BreakAndReportAbortMessage();
                        }
                        // 重置计时时间
                        Actuator.ResetTiming();
                        // 调用前置监听
                        OnPreListener();

                        this.Result = StepResult.NotAvailable;

                        this.Result = Actuator.InvokeStep(forceInvoke);
                        // 如果当前step被标记为记录状态,则返回状态信息
                        if (null != StepData && StepData.RecordStatus)
                        {
                            RecordRuntimeStatus();
                        }

                        // 调用后置监听
                        OnPostListener();
                        // 如果执行结果不是bool类型或者为False,或者没有下级节点,则退出当前循环
                        object returnValue   = Actuator.Return;
                        bool   conditionFail = !(returnValue is bool) || !(bool)returnValue;
                        if (conditionFail || null == StepData || !StepData.HasSubSteps)
                        {
                            return;
                        }
                        // 执行所有的下级Step
                        StepTaskEntityBase subStepEntity = SubStepRoot;
                        do
                        {
                            if (!forceInvoke && Context.Cancellation.IsCancellationRequested)
                            {
                                this.Result = StepResult.Abort;
                                return;
                            }
                            subStepEntity.Invoke(forceInvoke);
                        } while (null != (subStepEntity = subStepEntity.NextStep));
                    }
                }
                catch (TestflowLoopBreakException ex)
                {
                    ex.CalcDown();
                    // 如果计数大于0,则继续抛出到上层
                    if (ex.Count > 0)
                    {
                        throw;
                    }
                    // 如果是跳出当前循环,则return
                    if (ex.BreakLoop)
                    {
                        return;
                    }
                }
            }
        }
        public void Invoke(bool forceInvoke = false)
        {
            FailedInfo       failedInfo      = null;
            StepResult       lastStepResult  = StepResult.NotAvailable;
            StatusReportType finalReportType = StatusReportType.Failed;

            try
            {
                this.State = RuntimeState.Running;
                SequenceStatusInfo startStatusInfo = new SequenceStatusInfo(Index, _stepEntityRoot.GetStack(),
                                                                            StatusReportType.Start, RuntimeState.Running, StepResult.NotAvailable)
                {
                    ExecutionTime  = DateTime.Now,
                    ExecutionTicks = -1,
                    CoroutineId    = RootCoroutineId
                };
                _context.StatusQueue.Enqueue(startStatusInfo);

                StepTaskEntityBase stepEntity = _stepEntityRoot;
                do
                {
                    stepEntity.Invoke(forceInvoke);
                } while (null != (stepEntity = stepEntity.NextStep));
                SetResultState(out lastStepResult, out finalReportType, out failedInfo);
            }
            catch (TaskFailedException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (TestflowAssertException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (ThreadAbortException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // Abort异常不会在内部处理,需要在外部强制抛出
                currentStep?.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
            }
            catch (TargetInvocationException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex.InnerException, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (TestflowLoopBreakException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                // 如果包含内部异常,则说明发生了运行时错误,记录错误信息。
                if (null != ex.InnerException)
                {
                    FillFinalExceptionReportInfo(ex.InnerException, out finalReportType, out lastStepResult,
                                                 out failedInfo);
                    // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                    if (null != currentStep && currentStep.BreakIfFailed)
                    {
                        currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                    }
                }
                // 只是流程控制,记录结果信息后退出
                else
                {
                    SetResultState(out lastStepResult, out finalReportType, out failedInfo);
                }
            }
            catch (Exception ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出Exception到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.BreakIfFailed)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            finally
            {
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                // 发送结束事件,包括所有的ReturnData信息
                SequenceStatusInfo overStatusInfo = new SequenceStatusInfo(Index, currentStep.GetStack(),
                                                                           finalReportType, this.State, StepResult.Over, failedInfo)
                {
                    ExecutionTime  = DateTime.Now,
                    CoroutineId    = RootCoroutineId,
                    ExecutionTicks = 0
                };
                overStatusInfo.WatchDatas = _context.VariableMapper.GetReturnDataValues(_sequence);
                this._context.StatusQueue.Enqueue(overStatusInfo);

                _context.VariableMapper.ClearSequenceVariables(_sequence);
                this._stepEntityRoot = null;
                // 将失败步骤职责链以后的step标记为null
                currentStep.NextStep = null;
            }
        }