Exemplo n.º 1
0
        public void Signal_signal_then_wait_wait_wait()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();
            monitor.Signal();
            monitor.Signal();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(timeout, "timeout 1 should not have occurred");

            timeout = monitor.Wait(TimeSpan.FromSeconds(1));
            Assert.IsTrue(timeout, "timeout 2 should not have occurred");

            timeout = monitor.Wait(TimeSpan.FromSeconds(1));
            Assert.IsFalse(timeout, "timeout 3 should have occurred");
        }
Exemplo n.º 2
0
        public void Wait_then_timeout()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(0.1));

            Assert.IsFalse(timeout, "timeout should have occurred");
        }
Exemplo n.º 3
0
        public void Wait_then_Signal()
        {
            MonitorSemaphore monitor = new MonitorSemaphore();
            new Thread(() => {
                Thread.Sleep(100);
                monitor.Signal();
            }).Start();
            var timeout = monitor.Wait(TimeSpan.FromSeconds(3));

            Assert.IsTrue(timeout, "timeout should not have occurred");
        }