public void Dispose_is_idempotent() { MemoryChannel channel = new MemoryChannel(); channel.Dispose(); channel.Dispose(); }
public void Run() { this.logger.WriteLine("Receive loop with {0} senders, {1:0.0} sec, send before receive={2}, receive buffer={3}...", this.senderCount, this.duration.TotalSeconds, this.sendBeforeReceive, this.receiveBufferSize); MemoryChannel channel = new MemoryChannel(); int[] sentDataSizes = new int[] { 11, 19, 29, 41, 53, 71, 89, 101 }; using (CancellationTokenSource cts = new CancellationTokenSource()) { DataOracle oracle = new DataOracle(); Sender[] senders = this.CreateSenders(channel, sentDataSizes, oracle); ValidatingReceiver receiver = new ValidatingReceiver(channel, this.logger, this.receiveBufferSize, oracle); Task<long>[] senderTasks = new Task<long>[senders.Length]; Task<long> receiverTask = this.StartSendersAndReceiver(cts.Token, senders, receiver, senderTasks); Thread.Sleep(this.duration); cts.Cancel(); Task.WaitAll(senderTasks); channel.Dispose(); receiverTask.Wait(); ValidateTransferredByteCount(senderTasks, receiverTask); } this.logger.WriteLine("Done."); }
public void Dispose_after_create_causes_subsequent_send_and_receive_to_throw_ObjectDisposed() { MemoryChannel channel = new MemoryChannel(); channel.Dispose(); Assert.Throws <ObjectDisposedException>(() => channel.Send(new byte[1])); Assert.Throws <ObjectDisposedException>(() => channel.ReceiveAsync(new byte[1])); }
public void Dispose_completes_pending_receive_and_causes_subsequent_send_and_receive_to_throw_ObjectDisposed() { Task <int> receiveTask; MemoryChannel channel = new MemoryChannel(); receiveTask = AssertTaskPending(channel.ReceiveAsync(new byte[1])); channel.Dispose(); AssertTaskCompleted(0, receiveTask); Assert.Throws <ObjectDisposedException>(() => channel.Send(new byte[1])); Assert.Throws <ObjectDisposedException>(() => channel.ReceiveAsync(new byte[1])); }