示例#1
0
        public void Yield_ClosedChan_ShouldNotBeBlocked()
        {
            channel <int> sut      = new channel <int>(2);
            Task          producer = Task.Run(() =>
            {
                sut.Send(1);
                sut.Send(2);
                sut.Send(3);
            });

            List <int> items    = new List <int>();
            bool       called   = false;
            Task       consumer = Task.Run(() =>
            {
                foreach (int i in sut)
                {
                    items.Add(i);
                }
                called = true;
            });

            producer.Wait();
            sut.Close();
            consumer.Wait(m_awaitTimeout);

            Assert.AreEqual(3, items.Count);
            Assert.IsTrue(called);
        }
示例#2
0
        public void Receive_FromEmptyChanAfterClosed_ShouldThrow()
        {
            channel <int> sut = new channel <int>(2);

            sut.Close();
            Exception exception = null;

            try
            {
                sut.Receive();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.AreEqual(0, sut.Length);
            Assert.IsTrue(sut.IsClosed);
            Assert.IsInstanceOfType(exception, typeof(PanicException));
        }