示例#1
0
        public void Dequeue_while_dequeue_still_pending_throws_InvalidOperation()
        {
            InputQueue <string> queue = new InputQueue <string>();

            Task <string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            Assert.Throws <InvalidOperationException>(() => queue.DequeueAsync());
        }
示例#2
0
        private void StartWriteStream(InputQueue <string> redirectStandardIn, StreamWriter standardIn)
        {
            Task.Run(async() =>
            {
                // Write the contents as UTF8 to handle all characters.
                var utf8Writer = new StreamWriter(standardIn.BaseStream, new UTF8Encoding(false));

                while (!_processExitedCompletionSource.Task.IsCompleted)
                {
                    Task <string> dequeueTask = redirectStandardIn.DequeueAsync();
                    var completedTask         = await Task.WhenAny(dequeueTask, _processExitedCompletionSource.Task);
                    if (completedTask == dequeueTask)
                    {
                        string input = await dequeueTask;
                        if (!string.IsNullOrEmpty(input))
                        {
                            utf8Writer.WriteLine(input);
                            utf8Writer.Flush();
                        }
                    }
                }

                Trace.Info("STDIN stream write finished.");
            });
        }
示例#3
0
                public async Task WaitForBackgroundCloseAsync(CancellationToken token)
                {
                    Fx.Assert(backgroundCloseData != null, "Need to check background close first");
                    object dummy = await backgroundCloseData.DequeueAsync(token);

                    Fx.Assert(dummy == null, "we should get an exception or null");
                }
示例#4
0
        public void Multiple_enqueues_then_dequeues_complete_sync_in_order()
        {
            InputQueue<string> queue = new InputQueue<string>();

            queue.Enqueue("a");
            queue.Enqueue("b");

            Task<string> task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);

            task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("b", task.Result);
        }
示例#5
0
        public void Multiple_enqueues_then_dequeues_complete_sync_in_order()
        {
            InputQueue <string> queue = new InputQueue <string>();

            queue.Enqueue("a");
            queue.Enqueue("b");

            Task <string> task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);

            task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("b", task.Result);
        }
示例#6
0
        public void Enqueue_then_dequeue_repeated_twice_completes_sync()
        {
            InputQueue<string> queue = new InputQueue<string>();

            queue.Enqueue("a");

            Task<string> task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);

            queue.Enqueue("b");

            task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("b", task.Result);
        }
示例#7
0
        public void Enqueue_then_dequeue_repeated_twice_completes_sync()
        {
            InputQueue <string> queue = new InputQueue <string>();

            queue.Enqueue("a");

            Task <string> task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);

            queue.Enqueue("b");

            task = queue.DequeueAsync();

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("b", task.Result);
        }
示例#8
0
        public void Dispose_causes_subsequent_enqueue_and_dequeue_to_throw_ObjectDisposed()
        {
            InputQueue <string> queue = new InputQueue <string>();

            queue.Dispose();

            Assert.Throws <ObjectDisposedException>(() => queue.Enqueue("a"));
            Assert.Throws <ObjectDisposedException>(() => queue.DequeueAsync());
        }
示例#9
0
        public void Dequeue_completes_after_enqueue()
        {
            InputQueue<string> queue = new InputQueue<string>();
            
            Task<string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            queue.Enqueue("a");

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);
        }
示例#10
0
        public void Dequeue_completes_after_enqueue()
        {
            InputQueue <string> queue = new InputQueue <string>();

            Task <string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            queue.Enqueue("a");

            Assert.Equal(TaskStatus.RanToCompletion, task.Status);
            Assert.Equal("a", task.Result);
        }
示例#11
0
        public void Dispose_completes_pending_receive_with_ObjectDisposed()
        {
            InputQueue <string> queue = new InputQueue <string>();

            Task <string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            queue.Dispose();

            Assert.True(task.IsFaulted);
            Assert.NotNull(task.Exception);
            AggregateException ae = task.Exception;

            Assert.Equal(1, ae.InnerExceptions.Count);
            Assert.IsType <ObjectDisposedException>(ae.InnerExceptions[0]);
        }
示例#12
0
        public void Dispose_causes_subsequent_enqueue_and_dequeue_to_throw_ObjectDisposed()
        {
            InputQueue<string> queue = new InputQueue<string>();
            queue.Dispose();

            Assert.Throws<ObjectDisposedException>(() => queue.Enqueue("a"));
            Assert.Throws<ObjectDisposedException>(() => queue.DequeueAsync());
        }
示例#13
0
        public void Dispose_completes_pending_receive_with_ObjectDisposed()
        {
            InputQueue<string> queue = new InputQueue<string>();

            Task<string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            queue.Dispose();

            Assert.True(task.IsFaulted);
            Assert.NotNull(task.Exception);
            AggregateException ae = task.Exception;
            Assert.Equal(1, ae.InnerExceptions.Count);
            Assert.IsType<ObjectDisposedException>(ae.InnerExceptions[0]);
        }
示例#14
0
        public void Dequeue_while_dequeue_still_pending_throws_InvalidOperation()
        {
            InputQueue<string> queue = new InputQueue<string>();

            Task<string> task = queue.DequeueAsync();

            Assert.False(task.IsCompleted);

            Assert.Throws<InvalidOperationException>(() => queue.DequeueAsync());
        }
示例#15
0
 public override Task <TChannel> AcceptChannelAsync(CancellationToken token)
 {
     ThrowIfNotOpened();
     return(channelQueue.DequeueAsync(token));
 }