Exemple #1
0
        public void TestWorkflowProgressParallel()
        {
            //IWorkContext context = new WorkContext(null, TestEnvironment.Client);
            // defines and executes a distributed workflow
            var w = new ParallelStep();

            w.Initialise(_workContext);
            var p1 = new P1 {
                @from = 0, to = 2000, slice = 100
            };

            // 20 parallel slices
            // start and monitor
            _workContext.Logger.LogDebug("Starting...");
            _workContext.Logger.LogDebug("[{0}] {1}", "I", w.Progress);
            //P9 p9 = w.Execute(p1, TimeSpan.FromSeconds(10));
            AsyncResult <WorkflowOutput <P9> > ar = w.BeginExecute(p1, null);
            int loop = 0;

            while (!ar.IsCompleted)
            {
                Thread.Sleep(100);
                _workContext.Logger.LogDebug("[{0}] {1}", loop, w.Progress);
                loop++;
            }
            P9 p9 = ar.EndInvoke().Result;

            _workContext.Logger.LogDebug("[{0}] {1}", "Z", w.Progress);
            Assert.AreEqual(2001000, p9.total);
            _workContext.Logger.LogDebug("Complete.");
        }
Exemple #2
0
        public void TestWorkstepParallelOverride()
        {
            // defines and executes a distributed workflow
            var w = new ParallelStep();

            w.Initialise(_workContext);
            var p1 = new P1 {
                @from = 0, to = 2000, slice = 100
            };
            // 20 parallel slices
            P9 p9 = w.Execute(p1).Result;

            Assert.AreEqual(2001000, p9.total);
        }
Exemple #3
0
        public void TestStepWaitInfiniteAndAbortTest()
        {
            var plan     = new TestPlan();
            var parallel = new ParallelStep();
            var abort    = new TestStepAbortPlan()
            {
                WaitFor = new TestStepWaitInfinite()
            };

            parallel.ChildTestSteps.Add(abort);
            parallel.ChildTestSteps.Add(abort.WaitFor);
            plan.ChildTestSteps.Add(parallel);
            var run = plan.Execute();

            Assert.AreEqual(Verdict.Aborted, run.Verdict);
            foreach (var step in parallel.ChildTestSteps)
            {
                Assert.AreEqual(Verdict.Aborted, step.Verdict);
            }
        }
Exemple #4
0
        public void SweepRaceBug()
        {
            // test that validation rules can be checked while the test plan is running
            // without causing an error. The validation rules does not need to do actual validation
            // but since SweepLoop and SweepLoopRange modifies its child steps this could cause an error
            // as shown by SweepRaceBugCheckStep and SweepRaceBugStep.
            var plan   = new TestPlan();
            var repeat = new RepeatStep {
                Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count
            };
            var loop = new SweepLoop();

            repeat.ChildTestSteps.Add(loop);
            loop.ChildTestSteps.Add(new SweepRaceBugStep()
            {
            });
            loop.ChildTestSteps.Add(new SweepRaceBugCheckStep()
            {
            });
            var steptype = TypeData.FromType(typeof(SweepRaceBugStep));
            var member   = steptype.GetMember(nameof(SweepRaceBugStep.Frequency));
            var member2  = TypeData.FromType(typeof(SweepRaceBugCheckStep)).GetMember(nameof(SweepRaceBugCheckStep.Frequency2));

            var lst = new List <SweepParam>();

            double[] values = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            lst.Add(new SweepParam(new[] { member }, values.Cast <object>().ToArray()));
            lst.Add(new SweepParam(new[] { member2 }, values.Cast <object>().ToArray()));
            loop.SweepParameters = lst;

            var loopRange = new SweepLoopRange();

            loopRange.SweepStart  = 1;
            loopRange.SweepEnd    = 10;
            loopRange.SweepPoints = 10;
            loopRange.ChildTestSteps.Add(new SweepRaceBugStep()
            {
            });
            loopRange.ChildTestSteps.Add(new SweepRaceBugCheckStep()
            {
            });
            loopRange.SweepProperties = new List <IMemberData> {
                member, member2
            };
            var repeat2 = new RepeatStep {
                Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count
            };

            repeat2.ChildTestSteps.Add(loopRange);
            var parallel = new ParallelStep();

            plan.ChildTestSteps.Add(parallel);
            parallel.ChildTestSteps.Add(repeat);
            parallel.ChildTestSteps.Add(repeat2);

            TestPlanRun run = null;

            TapThread.Start(() => run = plan.Execute());
            TapThread.Start(() =>
            {
                while (run == null)
                {
                    loopRange.Error.ToList();
                }
            });
            while (run == null)
            {
                loop.Error.ToList();
            }

            Assert.AreEqual(Verdict.NotSet, run.Verdict);
        }
Exemple #5
0
        public void BeforeOpenExceptionTest(Type managerType, Type exceptionType, Verdict expectedVerdict, bool withParallel)
        {
            EngineSettings.Current.ResourceManagerType = (IResourceManager)Activator.CreateInstance(managerType);
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };

            InstrumentSettings.Current.Add(instr1);
            try
            {
                TestPlan  plan  = new TestPlan();
                ITestStep step1 = new InstrumentTestStep()
                {
                    Instrument = instr1
                };
                if (withParallel)
                {
                    var par = new ParallelStep();
                    par.ChildTestSteps.Add(step1);
                    step1 = par;
                }
                plan.Steps.Add(step1);
                ITestStep lastStep = new LogStep()
                {
                    Name = "Last Step", LogMessage = "Last Step Ran"
                };
                plan.Steps.Add(lastStep);
                UnitTestingLockManager.Enable();
                UnitTestingLockManager.BeforeOpenEffect = r => throw (Exception)Activator.CreateInstance(exceptionType, new string[] { "Custom exception message" });
                var logListener = new TestTraceListener();
                Log.AddListener(logListener);
                //string logFileName = Path.Combine(Path.GetDirectoryName(PluginManager.GetOpenTapAssembly().Location), $"BeforeOpenExceptionTest({managerType},{exceptionType},{withParallel}).txt");
                //if (File.Exists(logFileName)) File.Delete(logFileName);
                //var fileListener = new FileTraceListener(logFileName);
                //Log.AddListener(fileListener);
                try
                {
                    var run = plan.Execute();
                    Assert.AreEqual(expectedVerdict, run.Verdict);
                }
                finally
                {
                    Log.RemoveListener(logListener);
                    //Log.RemoveListener(fileListener);
                    UnitTestingLockManager.Disable();
                }

                // We should have the custom exception message in the log
                StringAssert.Contains("Custom exception message", logListener.GetLog());

                if (expectedVerdict == Verdict.Error)
                {
                    StringAssert.IsMatch(": Error .+Custom exception message", logListener.GetLog());
                }
                else
                {
                    StringAssert.IsMatch(": Warning .+Custom exception message", logListener.GetLog());
                }

                // The last step should not have run:
                if (exceptionType == typeof(OperationCanceledException))
                {
                    StringAssert.DoesNotContain("Last Step Ran", logListener.GetLog());
                }
            }
            finally
            {
                InstrumentSettings.Current.Remove(instr1);
            }
        }