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()); }
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."); }); }
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"); }
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); }
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); }
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); }
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); }
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()); }
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); }
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); }
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]); }
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()); }
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]); }
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()); }
public override Task <TChannel> AcceptChannelAsync(CancellationToken token) { ThrowIfNotOpened(); return(channelQueue.DequeueAsync(token)); }