Example #1
0
        public static void closing_the_channel_with_a_waiting_receiver_cancel_the_receivers_task(Test t)
        {
            var ch = new BufferedChannel <int>(3);
            var rt = ch.ReceiveAsync();

            if (rt == null)
            {
                t.Fatal("returned task was null");
            }
            if (rt.IsCompleted)
            {
                t.Fatal("returned task was complete already!");
            }
            ch.Close();
            try
            {
                if (!rt.Wait(100))
                {
                    t.Fatal("task did not completed");
                }
            }
            catch (AggregateException)
            {
                if (!rt.IsCanceled)
                {
                    t.Fatal("task is not cancelled");
                }
            }
        }
Example #2
0
        public static void closing_the_channel_with_a_waiting_sender_does_not_cancel_the_senders_task(Test t)
        {
            if (Tests.Short)
            {
                t.Skip();
            }

            var ch  = new BufferedChannel <int>(1);
            var st1 = ch.SendAsync(1);
            var st2 = ch.SendAsync(2);

            if (st2 == null)
            {
                t.Fatal("returned task was null");
            }
            if (st2.IsCompleted)
            {
                t.Fatal("returned task was complete already!");
            }
            ch.Close();
            if (st2.Wait(100))
            {
                t.Fatal("task completed, it should just wait");
            }
        }
Example #3
0
        public static void trySend_on_a_closed_channel_returns_false(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            ch.Close();
            if (ch.TrySend(2) != false)
            {
                t.Fatal("was able to send on closed channel");
            }
        }
Example #4
0
        public static void try_receive_on_a_closed_channel_return_false(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            ch.Close();
            int val;

            if (ch.TryReceive(out val) != false)
            {
                t.Fatal("was able to receive on closed channel");
            }
        }
Example #5
0
        public static void ReceiveAsync_on_a_closed_channel_return_cancelled_task(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            ch.Close();
            var rt = ch.ReceiveAsync();

            if (rt == null)
            {
                t.Fatal("ReceiveAsync returned null");
            }
            if (!rt.IsCanceled)
            {
                t.Fatal("ReceiveAsync is not cancelled");
            }
        }
Example #6
0
        public static void sendAsync_on_a_closed_channel_returns_a_cancelled_task(Test t)
        {
            var ch = new BufferedChannel <int>(3);

            ch.Close();
            var st = ch.SendAsync(2);

            if (st == null)
            {
                t.Fatal("returned task was null");
            }
            if (!st.IsCanceled)
            {
                t.Fatal("returned task was not cancelled");
            }
        }