示例#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.");
            }
        }
示例#2
0
        public override MessageBase GetHeartBeatMessage()
        {
            StatusMessage statusMessage = new StatusMessage(MessageNames.HeartBeatStatusName, Context.State, Context.SessionId)
            {
                Index = Context.MsgIndex
            };
            SessionTaskEntity sessionTaskEntity = Context.SessionTaskEntity;

            sessionTaskEntity.FillSequenceInfo(statusMessage);
            if (Context.GetProperty <bool>("EnablePerformanceMonitor"))
            {
                ModuleUtils.FillPerformance(statusMessage);
            }
            return(statusMessage);
        }
        private void RunSequences(SessionTaskEntity sessionTaskEntity)
        {
            switch (Context.ExecutionModel)
            {
            case ExecutionModel.SequentialExecution:
                for (int i = 0; i < sessionTaskEntity.SequenceCount; i++)
                {
                    Context.SessionTaskEntity.InvokeSequence(i);
                }
                break;

            case ExecutionModel.ParallelExecution:
                _blockEvent = new ManualResetEvent(false);
                _blockEvent.Reset();
                Thread.VolatileWrite(ref _overTaskCount, 0);
                _sequenceThreads = new List <Thread>(sessionTaskEntity.SequenceCount);
                for (int i = 0; i < sessionTaskEntity.SequenceCount; i++)
                {
                    Thread taskThread = new Thread(RunSingleSequence)
                    {
                        IsBackground = true,
                        Name         = string.Format(Constants.TaskThreadNameFormt, Context.SessionId, i)
                    };
                    _sequenceThreads.Add(taskThread);
                }
                ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                {
                    Thread.Sleep(10);
                    for (int i = 0; i < _sequenceThreads.Count; i++)
                    {
                        _sequenceThreads[i].Start(i);
                    }
                }));
                Thread.MemoryBarrier();
                _blockEvent.WaitOne();
                _blockEvent.Dispose();
                break;

            default:
                throw new InvalidOperationException();
            }
        }
        private void SendSetupFailedEvents(SessionTaskEntity sessionTaskEntity, RuntimeState sequenceState)
        {
            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, sequenceState, StepResult.NotAvailable,
                                                                          failedInfo)
                {
                    ExecutionTime  = DateTime.Now,
                    ExecutionTicks = -1,
                    CoroutineId    = sequenceTaskEntity.RootCoroutineId
                };
                Context.StatusQueue.Enqueue(statusInfo);
            }
        }
        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;
        }