Beispiel #1
0
        public IRunResult Run(IRunIntent intent)
        {
            _listener.OnRunStarted(intent);

            IRunResult result;

            try
            {
                var suiteResults = intent.Intents
                                   .Select(x => Tuple.Create(x, Assembly.LoadFrom(x.Identity.Relative)))
                                   .GroupBy(x => GetTestType(x.Item2))
                                   .OrderByDescending(x => x.Key)
                                   .SelectMany(
                    group => group
#if PARALLEL
                    .AsParallel()
                    .WithCancellation(intent.CancellationTokenSource.Token)
                    .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
#endif
                    .Select(x => RunAssemblySuites(x.Item2, intent.ShadowCopyPath, intent.CancellationTokenSource, x.Item1))).ToList();
                result = _resultFactory.CreateRunResult(intent, suiteResults);
            }
            catch (Exception exception)
            {
                _listener.OnError(ExceptionDescriptor.Create(exception));
                throw;
            }

            _listener.OnRunFinished(result);

            return(result);
        }
        private static void ExceptionDescriptorExporter(ExceptionDescriptor descriptor, JsonWriter writer)
        {
            writer.WriteObjectStart();  // exception
            writer.WritePropertyName("id");
            writer.Write(descriptor.Id);

            writer.WritePropertyName("message");
            writer.Write(descriptor.Message);

            writer.WritePropertyName("type");
            writer.Write(descriptor.Type);

            writer.WritePropertyName("remote");
            writer.Write(descriptor.Remote);

            writer.WritePropertyName("stack");

            writer.WriteArrayStart();   // stack

            StackFrame[] frames = descriptor.Stack;
            if (frames != null)
            {
                foreach (StackFrame frame in frames)
                {
                    writer.WriteObjectStart();  // trace
                    writer.WritePropertyName("path");
                    writer.Write(frame.GetFileName());
                    writer.WritePropertyName("line");
                    writer.Write(frame.GetFileLineNumber());
                    writer.WritePropertyName("label");
                    MethodBase method = frame.GetMethod();
                    string     label  = method.Name;
                    if (method.ReflectedType != null)
                    {
                        label = method.ReflectedType.FullName + "." + label;
                    }

                    writer.Write(label);
                    writer.WriteObjectEnd();    // trace
                }
            }

            writer.WriteArrayEnd();     // stack

            if (descriptor.Truncated > 0)
            {
                writer.WritePropertyName("truncated");
                writer.Write(descriptor.Truncated);
            }

            if (descriptor.Cause != null)
            {
                writer.WritePropertyName("cause");
                writer.Write(descriptor.Cause);
            }

            writer.WriteObjectEnd();    // exception
        }
        private void ReportResult(RemoteTask task, State state, ExceptionDescriptor exception, string desc)
        {
            if (exception == null)
            {
                _server.TaskFinished(task, string.Empty, state.ToTaskResult());
            }
            else
            {
                _server.TaskOutput(task, "MUUHU", TaskOutputType.STDERR);
                _server.TaskOutput(task, "MUUHU", TaskOutputType.DEBUGTRACE);
                _server.TaskOutput(task, "\u2713", TaskOutputType.STDOUT);
                _server.TaskOutput(task, "\u2717", TaskOutputType.STDOUT);
                _server.TaskException(task, new[] { exception.ToTaskException(desc) });

                _server.TaskOutput(task, "xxxxxxxxxxxxxxxxxxxxxxxxxx", TaskOutputType.STDOUT);
                _server.TaskException(task, new[] { exception.ToTaskException(desc) });

                _server.TaskFinished(task, exception.Type.Name, state.ToTaskResult());
            }
        }
        /// <summary>
        /// Visit each node in the cause chain. For each node:
        /// Determine if it has already been described in one of the child subsegments' causes. If so, link there.
        /// Otherwise, describe it and add it to the Cause and  returns the list of <see cref="ExceptionDescriptor"/>.
        /// </summary>
        /// <param name="e">The exception to be added</param>
        /// <param name="subsegments">The subsegments to search for existing exception descriptor.</param>
        /// <returns> List of <see cref="ExceptionDescriptor"/></returns>
        public List <ExceptionDescriptor> DescribeException(Exception e, IEnumerable <Subsegment> subsegments)
        {
            List <ExceptionDescriptor> result = new List <ExceptionDescriptor>();

            // First check if the exception has been described in subsegment
            ExceptionDescriptor ex = new ExceptionDescriptor();
            IEnumerable <ExceptionDescriptor> existingExceptionDescriptors = null;

            if (subsegments != null)
            {
                existingExceptionDescriptors = subsegments.Where(subsegment => subsegment.Cause != null && subsegment.Cause.IsExceptionAdded).SelectMany(subsegment => subsegment.Cause.ExceptionDescriptors);
            }

            ExceptionDescriptor existingDescriptor = null;

            if (existingExceptionDescriptors != null)
            {
                existingDescriptor = existingExceptionDescriptors.FirstOrDefault(descriptor => e.Equals(descriptor.Exception));
            }

            // While referencing exception from child, record id if exists or cause and return.
            if (existingDescriptor != null)
            {
                ex.Cause = existingDescriptor.Id != null ? existingDescriptor.Id : existingDescriptor.Cause;
                ex.Id    = null; // setting this to null since, cause is already populated with reference to downstream exception
                result.Add(ex);
                return(result);
            }

            // The exception is not described. Start describe it.
            ExceptionDescriptor curDescriptor = new ExceptionDescriptor();

            while (e != null)
            {
                curDescriptor.Exception = e;
                curDescriptor.Message   = e.Message;
                curDescriptor.Type      = e.GetType().Name;
                StackFrame[] frames = new StackTrace(e, true).GetFrames();
                if (frames != null && frames.Length > MaxStackFrameSize)
                {
                    curDescriptor.Truncated = frames.Length - MaxStackFrameSize;
                    curDescriptor.Stack     = new StackFrame[MaxStackFrameSize];
                    Array.Copy(frames, curDescriptor.Stack, MaxStackFrameSize);
                }
                else
                {
                    curDescriptor.Stack = frames;
                }

                if (IsRemoteException(e))
                {
                    curDescriptor.Remote = true;
                }

                result.Add(curDescriptor);

                e = e.InnerException;
                if (e != null)
                {
                    // Inner exception alreay described
                    ExceptionDescriptor innerExceptionDescriptor = existingExceptionDescriptors != null?existingExceptionDescriptors.FirstOrDefault(d => d.Exception.Equals(e)) : null;

                    if (innerExceptionDescriptor != null)
                    {
                        curDescriptor.Cause = innerExceptionDescriptor.Id;
                        e = null;
                    }
                    else
                    {
                        var newDescriptor = new ExceptionDescriptor();
                        curDescriptor.Cause = newDescriptor.Id;
                        curDescriptor       = newDescriptor;
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
 public ExceptionFacade(string message = null, System.Exception innerException = null)
     : base(message, innerException)
 {
     this.exceptionDescriptor = new CommonExceptionDescriptor(message);
 }
Beispiel #6
0
 public ExceptionFacade(ExceptionDescriptor exceptionDescriptor, System.Exception innerException = null)
     : base(null, innerException)
 {
     this.exceptionDescriptor = exceptionDescriptor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionDescriptorResult"/> class.
 /// </summary>
 /// <param name="value">The descriptor value to return.</param>
 public ExceptionDescriptorResult(ExceptionDescriptor value) : base(value)
 {
 }
Beispiel #8
0
 public static TaskException ToTaskException(this ExceptionDescriptor exception, string desc)
 {
     return(new TaskException("x" + desc + "\r\n" + exception.Type.FullName, desc + "\r\n" + exception.Message, exception.StackTrace));
 }