Example #1
0
        public void OperationQueueTest_ParallelDrain()
        {
            var operations = new List <IOperation> {
                new OperationStub(), new OperationStub(), null
            };

            var opList = new OperationList();

            foreach (var item in operations)
            {
                opList.AddOperation(item);
            }

            var processor = new TrackingOperationProcessor();

            var opQueue = new OperationFetcher.OperationQueue(() => opList, new OperationProcessorInfo
            {
                SupportsConcurrentProcessing = true,
                Callback = processor.Process
            });

            var task = opQueue.DrainAsync();

            for (int i = 0; i < operations.Count; i++)
            {
                // we are processing asynchronously
                // tell the list to provide an operation to the queue
                opList.CompleteOperation();

                if (i == operations.Count - 1)
                {
                    // the last null is not received
                    continue;
                }

                // the operation has been sent to the callback
                // the callback has not completed the task
                // the queue will continue (this loop will run)
                Assert.IsTrue(MiscUtility.WaitUntil(() => processor.GetOperations().Count == i + 1, TimeSpan.FromSeconds(1), 50));
                Assert.AreSame(operations[i], processor.GetOperations()[i].Item2);
            }

            // the task should be complete
            task.AssertWaitCompletes(500);
        }
Example #2
0
 private void WaitUntilHelper(Func <bool> func)
 {
     Assert.IsTrue(MiscUtility.WaitUntil(func, TimeSpan.FromSeconds(15), 50), "WaitUntilHelper");
 }