Esempio n. 1
0
        public void CanGetLatency()
        {
            var arr = new List <int>();

            ActionQueue <int> .Clear();

            // Start processing queue at the rate of one item every 11ms.
            var t = ActionQueue <int> .Consume(x =>
            {
                arr.Add(x);
                Thread.Sleep(11);
            });

            // Arrange to stop processing the queue in 0.1 sec
            ActionQueue <int> .Cancel(95);

            // Add ten items.
            Enumerable.Range(0, 10).ToList().ForEach(ActionQueue <int> .Enqueue);

            // Wait 0.1 sec.
            Thread.Sleep(100);

            var latency = ActionQueue <int> .GetLatencyInMilliseconds();

            // Wait 0.1 sec for the extra items to be processed in the event of the cancellation not working.
            Thread.Sleep(100);
            Assert.IsTrue(latency >= 100, string.Format("Latency was meant to be >= {0}ms but it was {1}ms.", 100, latency));
        }
Esempio n. 2
0
        public void CanCancelWithTimestampedConsume()
        {
            var arr = new List <Timestamped <int> >();

            ActionQueue <int> .Clear();

            // Start processing queue at the rate of one item every 11ms.
            var t = ActionQueue <int> .Consume(x =>
            {
                arr.Add(x);
                Thread.Sleep(11);
            });

            // Arrange to stop processing the queue in 0.1 sec
            ActionQueue <int> .Cancel(95);

            // Add ten items.
            Enumerable.Range(0, 10).ToList().ForEach(ActionQueue <int> .Enqueue);

            // Wait 0.1 sec.
            Thread.Sleep(100);

            // Add another hundred items. The consumer should be cancelled before this happens.
            Enumerable.Range(10, 100).ToList().ForEach(ActionQueue <int> .Enqueue);

            // Wait 0.1 sec for the extra items to be processed in the event of the cancellation not working.
            Thread.Sleep(100);
            Assert.AreEqual(9, arr.Count);
        }
Esempio n. 3
0
        public void CanProcessQueue()
        {
            var total = 0;

            ActionQueue <int> .Clear();

            // Start processing queue
            var task = ActionQueue <int> .Consume(x => total += x);

            // Arrange to stop processing the queue in 0.1 sec
            ActionQueue <int> .Cancel(100);

            // Add items to queue (this is almost instantaneous).
            Enumerable.Range(1, 10).ToList().ForEach(ActionQueue <int> .Enqueue);

            // Wait 0.1 sec for the cancellation to take effect.
            Thread.Sleep(100);
            Assert.AreEqual(55, total);
        }
Esempio n. 4
0
 public void reset()
 {
     aq.Cancel();
     aq.Clear();
     moveGroup(outsideY);
 }