Ejemplo n.º 1
0
        public void record_data()
        {
            var spec = new Specification
            {
                name = "Some Name"
            };

            var timings = new Timings();
            timings.Start(spec);
            using (timings.Subject("Fixture.Setup", "Math"))
            {
                using (timings.Subject("Grammar", "Adding"))
                {
                    using (timings.Subject("Fixture.Teardown", "Math"))
                    {
                        Thread.Sleep(100);
                    }
                }
            }

            var records = timings.Finish();

            records.Select(x => x.Subject).ShouldHaveTheSameElementsAs("Some Name", "Math", "Adding", "Math");

            records.Each(x => x.Duration.ShouldBeGreaterThan(0));
        }
        private SpecResults buildResults(SpecContext context, Timings timings)
        {
            if (Request.IsCancelled)
            {
                return(null);
            }

            var catastrophic = context?.CatastrophicException;

            if (catastrophic != null)
            {
                throw new StorytellerExecutionException(catastrophic);
            }

            Finished = !_timeout.IsCompleted && !Request.IsCancelled;

            if (_timeout.IsCompleted && !Request.IsCancelled)
            {
                var result = timeoutMessage(timings);

                if (context == null)
                {
                    var perf = timings.Finish();

                    return(new SpecResults
                    {
                        Counts = new Counts(0, 0, 1, 0),
                        Duration = timings.Duration,
                        Performance = perf.ToArray(),
                        Attempts = Request.Plan.Attempts,
                        Results = new IResultMessage[] { result },
                        WasAborted = false
                    });
                }


                context.LogResult(result, null);
                context.Cancel();
            }



            return(context.FinalizeResults(Request.Plan.Attempts));
        }
Ejemplo n.º 3
0
        private static SpecResults buildResultsForContextCreationFailure(SpecExecutionRequest request, Exception ex,
                                                                         Timings timings)
        {
            var result = new StepResult(request.Specification.id, ex)
            {
                position = Stage.context
            };
            var perf = timings.Finish();

            return(new SpecResults
            {
                Attempts = request.Plan.Attempts,
                Duration = timings.Duration,
                Performance = perf.ToArray(),
                Counts = new Counts(0, 0, 1, 0),
                Results = new IResultMessage[]
                {
                    result
                }
            });
        }
Ejemplo n.º 4
0
        private static SpecResults buildResultsForContextCreationFailure(SpecExecutionRequest request, Exception ex,
            Timings timings)
        {
            var result = new StepResult(request.Specification.id, ex) {position = Stage.context};
            var perf = timings.Finish();

            return new SpecResults
            {
                Attempts = request.Plan.Attempts,
                Duration = timings.Duration,
                Performance = perf.ToArray(),
                Counts = new Counts(0, 0, 1, 0),
                Results = new IResultMessage[]
                {
                    result
                }
            };
        }
Ejemplo n.º 5
0
        private SpecResults buildResults(SpecContext context, Timings timings )
        {
            if (Request.IsCancelled) return null;

            var catastrophic = context?.CatastrophicException;
            if (catastrophic != null)
            {
                throw new StorytellerExecutionException(catastrophic);
            }

            Finished = !_timeout.IsCompleted && !Request.IsCancelled;

            if (_timeout.IsCompleted && !Request.IsCancelled)
            {
                var result = timeoutMessage(timings);

                if (context == null)
                {
                    var perf = timings.Finish();

                    return new SpecResults
                    {
                        Counts = new Counts(0, 0, 1, 0),
                        Duration = timings.Duration,
                        Performance = perf.ToArray(),
                        Attempts = Request.Plan.Attempts,
                        Results = new IResultMessage[] { result },
                        WasAborted = false
                    };
                }


                context.LogResult(result);
                context.Cancel();
            }

            return context.FinalizeResults(Request.Plan.Attempts);
        }
Ejemplo n.º 6
0
        public SpecResults Execute()
        {
            _reset = new ManualResetEvent(false);

            _thread = new Thread(() =>
            {
                try
                {
                    execute();
                }

#if NET46
                catch (ThreadAbortException)
                {
                    // nothing, it's handled below
                }
#endif
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            })
            {
                Name = "StoryTeller-Test-Execution"
            };

            _thread.Start();

            var timedout = !_reset.WaitOne(_stopConditions.TimeoutInSeconds.Seconds());
            _finished = true;

            if (_wasCancelled)
            {
                return(null);
            }

            if (_catastrophicException != null)
            {
                throw new StorytellerExecutionException(_catastrophicException);
            }
            if (_context?.CatastrophicException != null)
            {
                throw new StorytellerExecutionException(_context.CatastrophicException);
            }



            if (timedout && !_wasCancelled)
            {
                var result = timeoutMessage();

                if (_context == null)
                {
                    var perf = _timings.Finish();

                    return(new SpecResults
                    {
                        Counts = new Counts(0, 0, 1, 0),
                        Duration = _timings.Duration,
                        Performance = perf.ToArray(),
                        Attempts = _request.Plan.Attempts,
                        Results = new IResultMessage[] { result },
                        WasAborted = false
                    });
                }


                _context.LogResult(result);
                _context.Cancel();
            }

            return(_context.FinalizeResults(_request.Plan.Attempts));;
        }