예제 #1
0
        public void ClosedChannelsWithDataShouldNotReportClosedUntilDrained()
        {
            for (var i = 0; i < 10000; i++)
            {
                var chan = new Chan <int>();

                var wait = new AutoResetEvent(false);

                GoFunc.Run(() =>
                {
                    chan.Send(1);
                    chan.Close();
                }, "send");

                bool ok = false, ok2 = false;
                int  actual = -1, actual2 = -1;

                GoFunc.Run(() =>
                {
                    actual  = chan.ReceiveOk(out ok);
                    actual2 = chan.ReceiveOk(out ok2);
                    wait.Set();
                }, "receive");

                wait.WaitOne();

                Assert.AreEqual(true, ok, string.Format("ok iteration {0}", i));
                Assert.AreEqual(1, actual, string.Format("actual iteration {0}", i));
                Assert.AreEqual(false, ok2, string.Format("ok2 iteration {0}", i));
                Assert.AreEqual(default(int), actual2, string.Format("actual2 iteration {0}", i));
            }
        }
예제 #2
0
        public void ClosedChannelsWithDataShouldNotReportClosedUntilDrained()
        {
            for (int i = 0; i < 10000; i++)
            {
                var chan = new Chan<int>();

                var wait = new AutoResetEvent(initialState: false);

                GoFunc.Run(() =>
                           {
                               chan.Send(1);
                               chan.Close();

                           }, "send");

                bool ok = false, ok2 = false;
                int actual = -1, actual2 = -1;

                GoFunc.Run(() =>
                           {
                               actual = chan.ReceiveOk(out ok);
                               actual2 = chan.ReceiveOk(out ok2);
                               wait.Set();
                           }, "receive");

                wait.WaitOne();

                Assert.AreEqual(true, ok, string.Format("ok iteration {0}", i));
                Assert.AreEqual(1, actual, string.Format("actual iteration {0}", i));
                Assert.AreEqual(false, ok2, string.Format("ok2 iteration {0}", i));
                Assert.AreEqual(default(int), actual2, string.Format("actual2 iteration {0}", i));
            }
        }