示例#1
0
        protected override void FlowTaskAction()
        {
            SendStartMessage();

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, $"Start run sequence {_sequenceIndex}.");

            Context.State = RuntimeState.Running;

            SessionTaskEntity sessionTaskEntity = Context.SessionTaskEntity;

            try
            {
                sessionTaskEntity.InvokeSetUp();
                RuntimeState setUpState = sessionTaskEntity.GetSequenceTaskState(CommonConst.SetupIndex);
                // 如果SetUp执行失败,则执行TearDown,且配置所有序列为失败状态,并发送所有序列都失败的信息
                if (CoreUtils.IsFailed(setUpState))
                {
                    // 打印状态日志
                    Context.LogSession.Print(LogLevel.Error, Context.SessionId, "Run setup failed.");
                    for (int i = 0; i < sessionTaskEntity.SequenceCount; i++)
                    {
                        SequenceTaskEntity sequenceTaskEntity = sessionTaskEntity.GetSequenceTaskEntity(i);
                        sequenceTaskEntity.State = RuntimeState.Failed;

                        FailedInfo         failedInfo    = new FailedInfo(Context.I18N.GetStr("SetUpFailed"), FailedType.SetUpFailed);
                        CallStack          sequenceStack = ModuleUtils.GetSequenceStack(i, sequenceTaskEntity.RootCoroutineId);
                        SequenceStatusInfo statusInfo    = new SequenceStatusInfo(i, sequenceStack,
                                                                                  StatusReportType.Failed, setUpState, StepResult.NotAvailable, failedInfo)
                        {
                            ExecutionTime  = DateTime.Now,
                            ExecutionTicks = -1,
                            CoroutineId    = sequenceTaskEntity.RootCoroutineId
                        };
                        Context.StatusQueue.Enqueue(statusInfo);
                    }
                }
                else
                {
                    sessionTaskEntity.InvokeSequence(_sequenceIndex);
                }
            }
            finally
            {
                sessionTaskEntity.InvokeTearDown();

                Context.State = RuntimeState.Over;
                this.Next     = null;

                SendOverMessage();

                // 打印状态日志
                Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Run single sequence over.");
            }
        }
        protected override void FlowTaskAction()
        {
            SendStartMessage();

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Start run all sequence.");

            Context.State = RuntimeState.Running;

            SessionTaskEntity sessionTaskEntity = Context.SessionTaskEntity;

            try
            {
                sessionTaskEntity.InvokeSetUp();
                RuntimeState setUpState = sessionTaskEntity.GetSequenceTaskState(CommonConst.SetupIndex);
                // 如果SetUp执行失败,则执行TearDown,且配置所有序列为失败状态,并发送所有序列都失败的信息
                if (CoreUtils.IsFailed(setUpState))
                {
                    // 打印状态日志
                    Context.LogSession.Print(LogLevel.Error, Context.SessionId, "Run setup failed.");
                    SendSetupFailedEvents(sessionTaskEntity, setUpState);
                }
                else
                {
                    RunSequences(sessionTaskEntity);
                }
            }
            finally
            {
                sessionTaskEntity.InvokeTearDown();

                Context.State = RuntimeState.Over;
                this.Next     = null;

                SendOverMessage();

                // 打印状态日志
                Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Test execution over.");
            }
        }
        protected override void FlowTaskAction()
        {
            SendStartMessage();

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Start test project setup.");

            Context.State = RuntimeState.Running;

            SessionTaskEntity sessionTaskEntity = Context.SessionTaskEntity;

            sessionTaskEntity.InvokeSetUp();
            RuntimeState setUpState = sessionTaskEntity.GetSequenceTaskState(CommonConst.SetupIndex);

            // 如果SetUp执行失败,则执行TearDown,且配置所有序列为失败状态,并发送所有序列都失败的信息
            if (CoreUtils.IsFailed(setUpState))
            {
                // 打印状态日志
                Context.LogSession.Print(LogLevel.Error, Context.SessionId, "Run testproject setup failed.");
                for (int i = 0; i < sessionTaskEntity.SequenceCount; i++)
                {
                    sessionTaskEntity.GetSequenceTaskEntity(i).State = RuntimeState.Failed;

                    FailedInfo         failedInfo = new FailedInfo(Context.I18N.GetStr("SetUpFailed"), FailedType.SetUpFailed);
                    SequenceStatusInfo statusInfo = new SequenceStatusInfo(i, ModuleUtils.GetSequenceStack(i, 0),
                                                                           StatusReportType.Failed, setUpState, StepResult.NotAvailable, failedInfo)
                    {
                        ExecutionTime  = DateTime.Now,
                        ExecutionTicks = -1,
                        CoroutineId    = 0
                    };
                    Context.StatusQueue.Enqueue(statusInfo);
                }

                sessionTaskEntity.InvokeTearDown();
                // 打印状态日志
                Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Teardown execution over.");

                return;
            }

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Testproject setup execution over.");

            this._wakeTimer = new Timer(WakeThreadWhenCtrlMessageCome, null, Constants.WakeTimerInterval,
                                        Constants.WakeTimerInterval);
            _blockEvent.WaitOne();

            if (null == Context.CtrlStartMessage)
            {
                Context.LogSession.Print(LogLevel.Error, Context.SessionId,
                                         "Receive CtrlMessage without RunTearDown parameter.");
            }

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Teardown execution start.");

            sessionTaskEntity.InvokeTearDown();

            // 打印状态日志
            Context.LogSession.Print(LogLevel.Info, Context.SessionId, "Teardown execution over.");

            SendOverMessage();

            Context.State = RuntimeState.Over;
            this.Next     = null;
        }