Пример #1
0
        public void PumpSynchronousAndAsynchronousEvents()
        {
            EventQueue q = new EventQueue();

            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "PumpSynchronousAndAsynchronousEvents";
                pump.Start();

                int       numberOfAsynchronousEvents   = 0;
                int       sumOfAsynchronousQueueLength = 0;
                const int Repetitions = 2;
                for (int i = 0; i < Repetitions; i++)
                {
                    foreach (Event e in events)
                    {
                        q.Enqueue(e);
                        if (e.IsSynchronous)
                        {
                            Assert.That(q.Count, Is.EqualTo(0));
                        }
                        else
                        {
                            sumOfAsynchronousQueueLength += q.Count;
                            numberOfAsynchronousEvents++;
                        }
                    }
                }

                Console.WriteLine("Average queue length: {0}", (float)sumOfAsynchronousQueueLength / numberOfAsynchronousEvents);
            }
        }
Пример #2
0
        public void StartStopEventPump( )
        {
            ManualResetEventSlim signal = new ManualResetEventSlim(false);

            eventPump.EventPumpStateChanged += (arg) => {
                signal.Set();
            };

            Task task = Task.Factory.StartNew(() => eventPump.Start());

            signal.Wait();
            signal.Reset();

            Assert.IsTrue(eventPump.IsRunning);

            // let it run
            Thread.Sleep(500);

            eventPump.Stop();
            signal.Wait();

            Assert.IsFalse(eventPump.IsRunning);

            signal.Dispose();
            task.Dispose();
        }
Пример #3
0
        public void EventPumpQueueLength(int numberOfProducers, bool producerDelay)
        {
            EventQueue q = new EventQueue();

            EventProducer[] producers = new EventProducer[numberOfProducers];
            for (int i = 0; i < numberOfProducers; i++)
            {
                producers[i] = new EventProducer(q, i, producerDelay);
            }

            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "EventPumpQueueLength";
                pump.Start();

                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Start();
                }
                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Join();
                }
                pump.Stop();
            }
            Assert.That(q.Count, Is.EqualTo(0));

            foreach (EventProducer p in producers)
            {
                Console.WriteLine(
                    "#Events: {0}, MaxQueueLength: {1}", p.SentEventsCount, p.MaxQueueLength);
                Assert.IsNull(p.Exception, "{0}", p.Exception);
            }
        }
Пример #4
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

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

            Context.Dispatcher.Dispatch(TopLevelWorkItem);
        }
Пример #5
0
        public void PumpPendingEventsAfterAutoStop()
        {
            EventQueue q = new EventQueue();

            EnqueueEvents(q);
            Event[] eventsAfterStop =
            {
                new OutputEvent(new TestOutput("foo", TestOutputType.Out)),
                new OutputEvent(new TestOutput("bar", TestOutputType.Trace)),
            };
            foreach (Event e in eventsAfterStop)
            {
                q.Enqueue(e);
            }

            QueuingEventListener el = new QueuingEventListener();

            using (EventPump pump = new EventPump(el, q, true))
            {
                pump.Name = "PumpPendingEventsAfterAutoStop";
                pump.Start();
                int tries = 10;
                while (--tries > 0 && q.Count > 0)
                {
                    Thread.Sleep(100);
                }

                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
            }
            Assert.That(el.Events.Count, Is.EqualTo(events.Length + eventsAfterStop.Length));
        }
Пример #6
0
        public void EventPumpQueueLength(int numberOfProducers, bool producerDelay)
        {
            EventQueue q = new EventQueue();
            EventProducer[] producers = new EventProducer[numberOfProducers];
            for (int i = 0; i < numberOfProducers; i++)
            {
                producers[i] = new EventProducer(q, i, producerDelay);
            }

            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "EventPumpQueueLength";
                pump.Start();

                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Start();
                }
                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Join();
                }
                pump.Stop();
            }
            Assert.That(q.Count, Is.EqualTo(0));

            foreach (EventProducer p in producers)
            {
                Console.WriteLine(
                    "#Events: {0}, MaxQueueLength: {1}", p.SentEventsCount, p.MaxQueueLength);
                Assert.IsNull(p.Exception, "{0}", p.Exception);
            }
        }
Пример #7
0
        private void StartPump(EventPump pump, int waitTime)
        {
            pump.Start();

            while (waitTime > 0 && !pump.Pumping)
            {
                Thread.Sleep(10);
                waitTime -= 10;
            }
        }
Пример #8
0
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        private 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 EventListenerTextWriter("Error", Console.Error));

#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])
            {
                try
                {
                    System.Diagnostics.Debugger.Launch();
                }
#if !NETSTANDARD1_6
                catch (SecurityException)
                {
                    TopLevelWorkItem.MarkNotRunnable("System.Security.Permissions.UIPermission is not set to start the debugger.");
                    return;
                }
#endif
                //System.Diagnostics.Debugger.Launch() not implemented on mono
                catch (NotImplementedException)
                {
                    TopLevelWorkItem.MarkNotRunnable("Debugger unavailable on this platform.");
                    return;
                }
            }

#if NET20 || NET35 || NET40 || NET45
            if (Settings.ContainsKey(FrameworkPackageSettings.PauseBeforeRun) &&
                (bool)Settings[FrameworkPackageSettings.PauseBeforeRun])
            {
                PauseBeforeRun();
            }
#endif

            Context.Dispatcher.Start(TopLevelWorkItem);
        }
Пример #9
0
        private static void CreateCoreDLNativeWindow( )
        {
            var window = new NativeWindow("CoreDL Native Window");

            using (EventPump eventPump = EventPump.Instance) {
                eventPump.Start(window);

                /*
                 * because EventPump was started with window, it will dispose
                 * of window when it disposes
                 * ***/
            }
        }
Пример #10
0
        /// <summary>
        /// Initiate the test run.
        /// </summary>
        private 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 EventListenerTextWriter("Error", Console.Error));

            // 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();
            }

            if (!System.Diagnostics.Debugger.IsAttached &&
                Settings.ContainsKey(FrameworkPackageSettings.DebugTests) &&
                (bool)Settings[FrameworkPackageSettings.DebugTests])
            {
                try
                {
                    System.Diagnostics.Debugger.Launch();
                }
                catch (SecurityException)
                {
                    TopLevelWorkItem.MarkNotRunnable("System.Security.Permissions.UIPermission must be granted in order to launch the debugger.");
                    return;
                }
                //System.Diagnostics.Debugger.Launch() not implemented on mono
                catch (NotImplementedException)
                {
                    TopLevelWorkItem.MarkNotRunnable("This platform does not support launching the debugger.");
                    return;
                }
            }

#if NETFRAMEWORK
            if (Settings.ContainsKey(FrameworkPackageSettings.PauseBeforeRun) &&
                (bool)Settings[FrameworkPackageSettings.PauseBeforeRun])
            {
                PauseBeforeRun();
            }
#endif

            Context.Dispatcher.Start(TopLevelWorkItem);
        }
Пример #11
0
 public void PumpEventsWithAutoStop()
 {
     EventQueue q = new EventQueue();
     EnqueueEvents( q );
     QueuingEventListener el = new QueuingEventListener();
     EventPump pump = new EventPump( el, q, true );
     pump.Start();
     int tries = 10;
     while( --tries > 0 && q.Count > 0 )
     {
         Thread.Sleep(100);
     }
     VerifyQueue( el.Events );
     Assert.IsFalse( pump.Pumping, "Pump failed to stop" );
 }
Пример #12
0
        /// <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);
        }
Пример #13
0
        public void PumpEventsWithAutoStop()
        {
            EventQueue q = new EventQueue();

            EnqueueEvents(q);
            QueuingEventListener el   = new QueuingEventListener();
            EventPump            pump = new EventPump(el, q, true);

            pump.Start();
            int tries = 10;

            while (--tries > 0 && q.Count > 0)
            {
                Thread.Sleep(100);
            }
            VerifyQueue(el.Events);
            Assert.IsFalse(pump.Pumping, "Pump failed to stop");
        }
Пример #14
0
        public void PumpEventsWithAutoStop()
        {
            EventQueue           q  = new EventQueue();
            QueuingEventListener el = new QueuingEventListener();

            using (EventPump pump = new EventPump(el, q, true))
            {
                pump.Name = "PumpEventsWithAutoStop";
                pump.Start();
                EnqueueEvents(q);
                int tries = 10;
                while (--tries > 0 && q.Count > 0)
                {
                    Thread.Sleep(100);
                }
                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
            }
        }
Пример #15
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, false))
                {
                    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();
            }
        }
Пример #16
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 && !NETSTANDARD1_6
            if (Settings.ContainsKey(FrameworkPackageSettings.PauseBeforeRun) &&
                (bool)Settings[FrameworkPackageSettings.PauseBeforeRun])
            {
                PauseBeforeRun();
            }
#endif

            Context.Dispatcher.Start(TopLevelWorkItem);
        }
Пример #17
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);
        }
        /// <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 levelOfParallelization = _settings.Contains("NumberOfTestWorkers")
                ? (int)_settings["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
        }
        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, false))
                {
                    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();
            }
        }
 public void PumpEventsWithAutoStop()
 {
      EventQueue q = new EventQueue();
     QueuingEventListener el = new QueuingEventListener();
     using (EventPump pump = new EventPump(el, q, true))
     {
         pump.Name = "PumpEventsWithAutoStop";
         pump.Start();
         EnqueueEvents(q);
         int tries = 10;
         while (--tries > 0 && q.Count > 0)
         {
             Thread.Sleep(100);
         }
         Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
     }
 }
        ///// <summary>
        ///// Count Test Cases using a filter
        ///// </summary>
        ///// <param name="filter">The filter to apply</param>
        ///// <returns>The number of test cases found</returns>
        //public int CountTestCases(TestFilter filter)
        //{
        //    return this.suite.CountTestCases(filter);
        //}

        /// <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
        }
        public void PumpPendingEventsAfterAutoStop()
        {
            EventQueue q = new EventQueue();
            EnqueueEvents(q);
            Event[] eventsAfterStop =
            {
                new OutputEvent(new TestOutput("foo", TestOutputType.Out)),
                new OutputEvent(new TestOutput("bar", TestOutputType.Trace)),
            };
            foreach (Event e in eventsAfterStop)
            {
                q.Enqueue(e);
            }

            QueuingEventListener el = new QueuingEventListener();
            using (EventPump pump = new EventPump(el, q, true))
            {
                pump.Name = "PumpPendingEventsAfterAutoStop";
                pump.Start();
                int tries = 10;
                while (--tries > 0 && q.Count > 0)
                {
                    Thread.Sleep(100);
                }

                Assert.That(pump.PumpState, Is.EqualTo(EventPumpState.Stopped));
            }
            Assert.That(el.Events.Count, Is.EqualTo(events.Length + eventsAfterStop.Length));
        }
 private static void StartPump(EventPump pump, int waitTime)
 {
     pump.Start();
     WaitForPumpToStart(pump, waitTime);
 }
Пример #24
0
 private static void StartPump(EventPump pump, int waitTime)
 {
     pump.Start();
     WaitForPumpToStart(pump, waitTime);
 }
        public void PumpSynchronousAndAsynchronousEvents()
        {
            EventQueue q = new EventQueue();
            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "PumpSynchronousAndAsynchronousEvents";
                pump.Start();

                int numberOfAsynchronousEvents = 0;
                int sumOfAsynchronousQueueLength = 0;
                const int Repetitions = 2;
                for (int i = 0; i < Repetitions; i++)
                {
                    foreach (Event e in events)
                    {
                        q.Enqueue(e);
                        if (e.IsSynchronous)
                        {
                            Assert.That(q.Count, Is.EqualTo(0));
                        }
                        else
                        {
                            sumOfAsynchronousQueueLength += q.Count;
                            numberOfAsynchronousEvents++;
                        }
                    }
                }

                Console.WriteLine("Average queue length: {0}", (float)sumOfAsynchronousQueueLength / numberOfAsynchronousEvents);
            }
        }
Пример #26
0
 /// <summary>
 /// Windowless
 /// </summary>
 public virtual void Run( )
 {
     eventPump.Start();
 }
Пример #27
0
        private void StartPump( EventPump pump, int waitTime )
        {
            pump.Start();

            while( waitTime > 0 && !pump.Pumping )
            {
                Thread.Sleep( 10 );
                waitTime -= 10;
            }
        }