Beispiel #1
0
        /// <summary>
        /// Execute the TestPlan as specified. Blocking.
        /// </summary>
        /// <param name="resultListeners">ResultListeners for result outputs.</param>
        /// <param name="metaDataParameters">Optional metadata parameters.</param>
        /// <param name="stepsOverride">Sub-section of test plan to be executed. Note this might include child steps of disabled parent steps.</param>
        /// <returns>TestPlanRun results, no StepResults.</returns>
        public TestPlanRun Execute(IEnumerable <IResultListener> resultListeners, IEnumerable <ResultParameter> metaDataParameters = null, HashSet <ITestStep> stepsOverride = null)
        {
            TestPlanRun run = null;

            TapThread.WithNewContext(() => run = this.DoExecute(resultListeners, metaDataParameters, stepsOverride));
            return(run);
        }
Beispiel #2
0
        public void Run2()
        {
            var steps = EnabledChildSteps.ToArray();

            SemaphoreSlim sem = new SemaphoreSlim(0);
            var           trd = TapThread.Current;

            Log.Info("Starting {0} child steps in separate threads.", steps.Length);
            foreach (var _step in steps)
            {
                var step = _step;
                TapThread.Start(() =>
                {
                    try
                    {
                        RunChildStep(step);
                    }
                    catch
                    {
                        // no need to do anything. This thread will end now.
                        TapThread.WithNewContext(trd.Abort, null);
                    }
                    finally
                    {
                        sem.Release();
                    }
                });
            }

            for (int waits = 0; waits < steps.Length; waits++)
            {
                sem.Wait();
            }
        }
Beispiel #3
0
        public void BreakAbortStepRunNull()
        {
            TestPlan     testPlan = new TestPlan();
            SequenceStep step1    = new SequenceStep();
            SequenceStep step2    = new SequenceStep();
            SequenceStep step3    = new SequenceStep();

            testPlan.Steps.Add(step1);
            testPlan.Steps.Add(step2);
            testPlan.Steps.Add(step3);

            TapThread.WithNewContext(() =>
            {
                var planThread         = TapThread.Current;
                testPlan.BreakOffered += (s, e) => planThread.Abort();
                testPlan.Execute();
                Assert.IsTrue(TapThread.Current.AbortToken.IsCancellationRequested);
            });
            Assert.IsFalse(TapThread.Current.AbortToken.IsCancellationRequested);

            foreach (var step in testPlan.Steps)
            {
                Assert.IsNull(step.StepRun);
            }
        }
Beispiel #4
0
        public void HierarchyLocalWithThreads()
        {
            // This test verifies that ThreadHierarchyLocal work with different thread contexts.
            //
            tapThreadLocalObject.LocalValue = (int)5;
            // At child thread level it should be 5.
            TapThread.WithNewContext(() => Assert.AreEqual(5, (int)tapThreadLocalObject.LocalValue));
            TapThread.WithNewContext(() =>
            {
                tapThreadLocalObject.LocalValue = (int)6;
                // At child-child thread level it should be 6.
                TapThread.WithNewContext(() => Assert.AreEqual(6, (int)tapThreadLocalObject.LocalValue));
            });

            // At this level it should still be 5.
            TapThread.WithNewContext(() => Assert.AreEqual(5, (int)tapThreadLocalObject.LocalValue));

            // for no parent it should not have been set.
            TapThread.WithNewContext(() => Assert.IsNull(tapThreadLocalObject.LocalValue), parent: null);
        }
Beispiel #5
0
 public override void Run()
 {
     TapThread.WithNewContext(Run2);
 }