Ejemplo n.º 1
0
        public void SendEvents()
        {
            QueuingEventListener el = new QueuingEventListener();

            SendEvents(el);
            VerifyQueue(el.Events);
        }
Ejemplo n.º 2
0
        public void PumpEvents()
        {
            EventQueue           q  = new EventQueue();
            QueuingEventListener el = new QueuingEventListener();

            using (EventPump pump = new EventPump(el, q))
            {
                pump.Name = "PumpEvents";
                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
                StartPump(pump, 1000);
                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Pumping));
                EnqueueEvents(q);
                StopPump(pump, 1000);
                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
            }
            VerifyQueue(el.Events);
        }
Ejemplo n.º 3
0
        public void TracingEventListenerDoesNotDeadlock()
        {
            QueuingEventListener upstreamListener      = new QueuingEventListener();
            EventQueue           upstreamListenerQueue = upstreamListener.Events;

            // Install a TraceListener sending TestOutput events to the upstreamListener.
            // This simulates RemoteTestRunner.StartTextCapture, where TestContext installs such a TraceListener.
            TextWriter    traceWriter       = new EventListenerTextWriter(upstreamListener, TestOutputType.Trace);
            const string  TraceListenerName = "TracingEventListenerDoesNotDeadlock";
            TraceListener feedingTraceToUpstreamListener = new TextWriterTraceListener(traceWriter, TraceListenerName);

            try
            {
                Trace.Listeners.Add(feedingTraceToUpstreamListener);

                // downstreamListenerToTrace simulates an EventListener installed e.g. by an Addin,
                // which may call Trace within the EventListener methods:
                TracingEventListener downstreamListenerToTrace = new TracingEventListener();
                using (EventPump pump = new EventPump(downstreamListenerToTrace, upstreamListenerQueue))
                {
                    pump.Name = "TracingEventListenerDoesNotDeadlock";
                    pump.Start();

                    const int Repetitions = 10;
                    for (int i = 0; i < Repetitions; i++)
                    {
                        foreach (Event e in events)
                        {
                            Trace.WriteLine("Before sending {0} event.", e.GetType().Name);
                            e.Send(upstreamListener);
                            Trace.WriteLine("After sending {0} event.", e.GetType().Name);
                        }
                    }
                }
            }
            finally
            {
                Trace.Listeners.Remove(TraceListenerName);
                feedingTraceToUpstreamListener.Dispose();
            }
        }
Ejemplo n.º 4
0
 public void PumpEvents()
 {
     EventQueue q = new EventQueue();
     QueuingEventListener el = new QueuingEventListener();
     using (EventPump pump = new EventPump(el, q))
     {
         pump.Name = "PumpEvents";
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
         StartPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Pumping));
         EnqueueEvents(q);
         StopPump(pump, 1000);
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
     }
     VerifyQueue(el.Events);
 }
Ejemplo n.º 5
0
 public void SendEvents()
 {
     QueuingEventListener el = new QueuingEventListener();
     SendEvents(el);
     VerifyQueue(el.Events);
 }
        /// <summary>
        /// Run selected tests and return a test result. The test is run synchronously,
        /// and the listener interface is notified as it progresses.
        /// </summary>
        /// <param name="listener">Interface to receive EventListener notifications.</param>
        /// <param name="filter">A test filter used to select tests to be run</param>
        /// <returns></returns>
        public ITestResult Run(ITestListener listener, ITestFilter filter)
        {
            log.Info("Running tests");
            if (_loadedTest == null)
                throw new InvalidOperationException("Run was called but no test has been loaded.");

            // Save Console.Out and Error for later restoration
            TextWriter savedOut = Console.Out;
            TextWriter savedErr = Console.Error;

            TestExecutionContext initialContext = CreateTestExecutionContext(_settings);

#if NUNITLITE
            initialContext.Listener = listener;

            WorkItem workItem = WorkItem.CreateWorkItem(_loadedTest, initialContext, filter);
            workItem.Completed += new EventHandler(OnRunCompleted);
            workItem.Execute();

            _runComplete.WaitOne();

            return workItem.Result;
#else
            QueuingEventListener queue = new QueuingEventListener();

            if (_settings.Contains("CaptureStandardOutput"))
                initialContext.Out = new EventListenerTextWriter(queue, TestOutputType.Out);
            if (_settings.Contains("CapureStandardError"))
                initialContext.Error = new EventListenerTextWriter(queue, TestOutputType.Error);

            initialContext.Listener = queue;

            int numWorkers = _settings.Contains("NumberOfTestWorkers")
                ? (int)_settings["NumberOfTestWorkers"]
                : 0;

            WorkItemDispatcher dispatcher = null;

            if (numWorkers > 0)
            {
                dispatcher = new WorkItemDispatcher(numWorkers);
                initialContext.Dispatcher = dispatcher;
            }

            WorkItem workItem = WorkItem.CreateWorkItem(_loadedTest, initialContext, filter);
            workItem.Completed += new EventHandler(OnRunCompleted);

            using (EventPump pump = new EventPump(listener, queue.Events))
            {
                pump.Start();

                if (dispatcher != null)
                {
                    dispatcher.Dispatch(workItem);
                    dispatcher.Start();
                }
                else
                    workItem.Execute();

                _runComplete.WaitOne();
            }

            Console.SetOut(savedOut);
            Console.SetError(savedErr);

            if (dispatcher != null)
            {
                dispatcher.Stop();
                dispatcher = null;
            }

            return workItem.Result;
#endif
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        public void StartRun(ITestListener listener)
        {
#if !SILVERLIGHT && !NETCF && !PORTABLE
            // Save Console.Out and Error for later restoration
            _savedOut = Console.Out;
            _savedErr = Console.Error;

            Console.SetOut(new TextCapture(Console.Out));
            Console.SetError(new TextCapture(Console.Error));
#endif

#if PARALLEL
            QueuingEventListener queue = new QueuingEventListener();
            Context.Listener = queue;

            _pump = new EventPump(listener, queue.Events);
            _pump.Start();
#else
            Context.Dispatcher = new SimpleWorkItemDispatcher();
#endif

            Context.Dispatcher.Dispatch(TopLevelWorkItem);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        public void StartRun(ITestListener listener)
        {
#if !SILVERLIGHT && !NETCF && !PORTABLE
            // Save Console.Out and Error for later restoration
            _savedOut = Console.Out;
            _savedErr = Console.Error;

            Console.SetOut(new TextCapture(Console.Out));
            Console.SetError(new TextCapture(Console.Error));
#endif

#if PARALLEL
            // Queue and pump events, unless settings have SynchronousEvents == false
            if (!Settings.Contains(PackageSettings.SynchronousEvents) || !(bool)Settings[PackageSettings.SynchronousEvents])
            {
                QueuingEventListener queue = new QueuingEventListener();
                Context.Listener = queue;

                _pump = new EventPump(listener, queue.Events);
                _pump.Start();
            }
#endif

            if (!System.Diagnostics.Debugger.IsAttached &&
                Settings.Contains(PackageSettings.DebugTests) &&
                (bool)Settings[PackageSettings.DebugTests])
            {
                System.Diagnostics.Debugger.Launch();
            }

            Context.Dispatcher.Dispatch(TopLevelWorkItem);
        }
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        public override void StartRun(ITestListener listener)
        {
            // Save Console.Out and Error for later restoration
            _savedOut = Console.Out;
            _savedErr = Console.Error;

            QueuingEventListener queue = new QueuingEventListener();

            if (Settings.Contains(DriverSettings.CaptureStandardOutput))
                Context.Out = new EventListenerTextWriter(queue, TestOutputType.Out);
            if (Settings.Contains(DriverSettings.CaptureStandardError))
                Context.Error = new EventListenerTextWriter(queue, TestOutputType.Error);

            Context.Listener = queue;

            using (EventPump pump = new EventPump(listener, queue.Events))
            {
                pump.Start();

                Context.Dispatcher.Dispatch(TopLevelWorkItem);
            }
        }
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        public override void StartRun(ITestListener listener)
        {
            // Save Console.Out and Error for later restoration
            _savedOut = Console.Out;
            _savedErr = Console.Error;

            Console.SetOut(new TextCapture(Console.Out));
            Console.SetError(new TextCapture(Console.Error));

            QueuingEventListener queue = new QueuingEventListener();
            Context.Listener = queue;

            _pump = new EventPump(listener, queue.Events);
            _pump.Start();

            Context.Dispatcher.Dispatch(TopLevelWorkItem);
        }
Ejemplo n.º 11
0
        public void TracingEventListenerDoesNotDeadlock()
        {
            QueuingEventListener upstreamListener = new QueuingEventListener();
            EventQueue upstreamListenerQueue = upstreamListener.Events;

            // Install a TraceListener sending TestOutput events to the upstreamListener.
            // This simulates RemoteTestRunner.StartTextCapture, where TestContext installs such a TraceListener.
            TextWriter traceWriter = new EventListenerTextWriter(upstreamListener, TestOutputType.Trace);
            const string TraceListenerName = "TracingEventListenerDoesNotDeadlock";
            TraceListener feedingTraceToUpstreamListener = new TextWriterTraceListener(traceWriter, TraceListenerName);

            try
            {
                Trace.Listeners.Add(feedingTraceToUpstreamListener);

                // downstreamListenerToTrace simulates an EventListener installed e.g. by an Addin, 
                // which may call Trace within the EventListener methods:
                TracingEventListener downstreamListenerToTrace = new TracingEventListener();
                using (EventPump pump = new EventPump(downstreamListenerToTrace, upstreamListenerQueue))
                {
                    pump.Name = "TracingEventListenerDoesNotDeadlock";
                    pump.Start();

                    const int Repetitions = 10;
                    for (int i = 0; i < Repetitions; i++)
                    {
                        foreach (Event e in events)
                        {
                            Trace.WriteLine("Before sending {0} event.", e.GetType().Name);
                            e.Send(upstreamListener);
                            Trace.WriteLine("After sending {0} event.", e.GetType().Name);
                        }
                    }
                }
            }
            finally
            {
                Trace.Listeners.Remove(TraceListenerName);
                feedingTraceToUpstreamListener.Dispose();
            }
        }
        /// <summary>
        /// Run selected tests and return a test result. The test is run synchronously,
        /// and the listener interface is notified as it progresses.
        /// </summary>
        /// <param name="listener">Interface to receive EventListener notifications.</param>
        /// <param name="filter">A test filter used to select tests to be run</param>
        /// <returns></returns>
        public ITestResult Run(ITestListener listener, ITestFilter filter)
        {
            log.Info("Running tests");
            if (_loadedTest == null)
                throw new InvalidOperationException("The Run method was called but no test has been loaded");

            // Save Console.Out and Error for later restoration
            TextWriter savedOut = Console.Out;
            TextWriter savedErr = Console.Error;

            TestExecutionContext initialContext = CreateTestExecutionContext(_settings);

#if NUNITLITE
            initialContext.Listener = listener;

            WorkItem workItem = WorkItem.CreateWorkItem(_loadedTest, initialContext, filter);
            workItem.Completed += new EventHandler(OnRunCompleted);
            workItem.Execute();

            _runComplete.WaitOne();

            return workItem.Result;
#else
            QueuingEventListener queue = new QueuingEventListener();

            if (_settings.Contains(DriverSettings.CaptureStandardOutput))
                initialContext.Out = new EventListenerTextWriter(queue, TestOutputType.Out);
            if (_settings.Contains(DriverSettings.CaptureStandardError))
                initialContext.Error = new EventListenerTextWriter(queue, TestOutputType.Error);

            initialContext.Listener = queue;

            int levelOfParallelization = _settings.Contains(DriverSettings.NumberOfTestWorkers)
                ? (int)_settings[DriverSettings.NumberOfTestWorkers]
                : _loadedTest.Properties.ContainsKey(PropertyNames.LevelOfParallelization)
                    ? (int)_loadedTest.Properties.Get(PropertyNames.LevelOfParallelization)
                    : Math.Max(Environment.ProcessorCount, 2);

            WorkItemDispatcher dispatcher = null;

            if (levelOfParallelization > 0)
            {
                dispatcher = new WorkItemDispatcher(levelOfParallelization);
                initialContext.Dispatcher = dispatcher;
                // Assembly does not have IApplyToContext attributes applied
                // when the test is built, so  we do it here.
                // TODO: Generalize this
                if (_loadedTest.Properties.ContainsKey(PropertyNames.ParallelScope))
                    initialContext.ParallelScope = 
                        (ParallelScope)_loadedTest.Properties.Get(PropertyNames.ParallelScope) & ~ParallelScope.Self;
            }

            WorkItem workItem = WorkItem.CreateWorkItem(_loadedTest, initialContext, filter);
            workItem.Completed += new EventHandler(OnRunCompleted);

            using (EventPump pump = new EventPump(listener, queue.Events))
            {
                pump.Start();

                if (dispatcher != null)
                {
                    dispatcher.Dispatch(workItem);
                    dispatcher.Start();
                }
                else
                    workItem.Execute();

                _runComplete.WaitOne();
            }

            Console.SetOut(savedOut);
            Console.SetError(savedErr);

            if (dispatcher != null)
            {
                dispatcher.Stop();
                dispatcher = null;
            }

            return workItem.Result;
#endif
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        private void StartRun(ITestListener listener)
        {
#if !PORTABLE
            // Save Console.Out and Error for later restoration
            _savedOut = Console.Out;
            _savedErr = Console.Error;

            Console.SetOut(new TextCapture(Console.Out));
            Console.SetError(new EventListenerTextWriter("Error", Console.Error));
#endif

#if PARALLEL
            // Queue and pump events, unless settings have SynchronousEvents == false
            if (!Settings.ContainsKey(FrameworkPackageSettings.SynchronousEvents) || !(bool)Settings[FrameworkPackageSettings.SynchronousEvents])
            {
                QueuingEventListener queue = new QueuingEventListener();
                Context.Listener = queue;

                _pump = new EventPump(listener, queue.Events);
                _pump.Start();
            }
#endif

            if (!System.Diagnostics.Debugger.IsAttached &&
                Settings.ContainsKey(FrameworkPackageSettings.DebugTests) &&
                (bool)Settings[FrameworkPackageSettings.DebugTests])
                System.Diagnostics.Debugger.Launch();

#if !PORTABLE
            if (Settings.ContainsKey(FrameworkPackageSettings.PauseBeforeRun) &&
                (bool)Settings[FrameworkPackageSettings.PauseBeforeRun])
                PauseBeforeRun();

#endif

            Context.Dispatcher.Dispatch(TopLevelWorkItem);
        }