コード例 #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);
        }
コード例 #2
0
        public void OperationQueueTest_DrainTaskIsCompletedWhenNullOperationIsReceived()
        {
            var opList = new OperationList();

            opList.AddOperation(null);

            var processor = new TrackingOperationProcessor();

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

            var task = opQueue.DrainAsync();

            opList.CompleteOperation();

            // the task should be complete
            task.AssertWaitCompletes(500);
        }