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));
        }
示例#2
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);
        }
示例#3
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));;
        }