Esempio n. 1
0
        private void ExecuteTestStep(BizUnitTestStepWrapper stepWrapper, TestStage stage)
        {
            try
            {
                // Should this step be executed concurrently?
                if (stepWrapper.RunConcurrently)
                {
                    _logger.TestStepStart(stepWrapper.TypeName, DateTime.Now, true, stepWrapper.FailOnError);
                    Interlocked.Increment(ref _inflightQueueDepth);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerThreadThunk), new ConcurrentTestStepWrapper(stepWrapper, _context));
                }
                else
                {
                    _logger.TestStepStart(stepWrapper.TypeName, DateTime.Now, false, stepWrapper.FailOnError);
                    stepWrapper.Execute(_context);
                }
            }
            catch (Exception e)
            {
                _logger.TestStepEnd(stepWrapper.TypeName, DateTime.Now, e);

                if (stepWrapper.FailOnError)
                {
                    if (e is ValidationStepExecutionException)
                    {
                        throw;
                    }
                    else
                    {
                        var tsee = new TestStepExecutionException("BizUnit encountered an error executing a test step", e, stage, _testName, stepWrapper.TypeName);
                        throw tsee;
                    }
                }
            }

            if (!stepWrapper.RunConcurrently)
            {
                _logger.TestStepEnd(stepWrapper.TypeName, DateTime.Now, null);
            }

            FlushConcurrentQueue(false, stage);
        }
Esempio n. 2
0
        private void FlushConcurrentQueue(bool waitingToFinish, TestStage stage)
        {
            if (waitingToFinish && _inflightQueueDepth == 0)
            {
                return;
            }

            while ((_completedConcurrentSteps.Count > 0) || waitingToFinish)
            {
                object obj = null;

                lock (_completedConcurrentSteps.SyncRoot)
                {
                    if (_completedConcurrentSteps.Count > 0)
                    {
                        try
                        {
                            obj = _completedConcurrentSteps.Dequeue();
                        }
                        catch (Exception ex)
                        {
                            _logger.LogException(ex);
                        }
                    }
                }

                if (null != obj)
                {
                    var step = (ConcurrentTestStepWrapper)obj;
                    _logger.LogBufferedText(step.Logger);

                    _logger.TestStepEnd(step.Name, DateTime.Now, step.FailureException);

                    // Check to see if the test step failed, if it did throw the exception...
                    if (null != step.FailureException)
                    {
                        Interlocked.Decrement(ref _inflightQueueDepth);

                        if (step.FailOnError)
                        {
                            if (step.FailureException is ValidationStepExecutionException)
                            {
                                throw step.FailureException;
                            }
                            else
                            {
                                var tsee = new TestStepExecutionException("BizUnit encountered an error concurrently executing a test step", step.FailureException, stage, _testName, step.StepName);
                                throw tsee;
                            }
                        }
                    }
                    else
                    {
                        Interlocked.Decrement(ref _inflightQueueDepth);
                    }
                }

                if (waitingToFinish && (_inflightQueueDepth > 0))
                {
                    Thread.Sleep(250);
                }
                else if (waitingToFinish && (_inflightQueueDepth == 0))
                {
                    break;
                }
            }
        }
Esempio n. 3
0
        private void ExecuteXamlTestStep(TestStepBase testStep, TestStage stage)
        {
            try
            {
                // Should this step be executed concurrently?
                if (testStep.RunConcurrently)
                {
                    _context.LogInfo("Queuing concurrent step: {0} for execution", testStep.GetType().ToString());
                    Interlocked.Increment(ref _inflightQueueDepth);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerThreadThunk), new ConcurrentTestStepWrapper(testStep, _context));
                }
                else
                {
                    _logger.TestStepStart(testStep.GetType().ToString(), DateTime.Now, false, testStep.FailOnError);
                    if (testStep is ImportTestCaseStep)
                    {
                        ExecuteImportedTestCase(testStep as ImportTestCaseStep, _context);
                    }
                    else
                    {
                        testStep.Execute(_context);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.TestStepEnd(testStep.GetType().ToString(), DateTime.Now, e);

                if (testStep.FailOnError)
                {
                    if (e is ValidationStepExecutionException)
                    {
                        throw;
                    }

                    var tsee = new TestStepExecutionException("BizUnit encountered an error executing a test step", e, stage, _testName, testStep.GetType().ToString());
                    throw tsee;
                }
            }

            if (!testStep.RunConcurrently)
            {
                _logger.TestStepEnd(testStep.GetType().ToString(), DateTime.Now, null);
            }

            FlushConcurrentQueue(false, stage);
        }