[Test] public void AwaitUntilTimeoutWithoutSignal([Values(true, false)] bool isFair)
        {
            _lock = new ReentrantLock(isFair);
            ICondition c = _lock.NewCondition();

            _lock.Lock();
            DateTime until  = DateTime.UtcNow.AddMilliseconds(10);
            bool     result = c.AwaitUntil(until);

            Assert.That(DateTime.UtcNow, Is.GreaterThanOrEqualTo(until));
            Assert.IsFalse(result);
            _lock.Unlock();
        }
Ejemplo n.º 2
0
 public void Run()
 {
     try
     {
         myLock.WriterLock.Lock();
         c.AwaitUntil(DateTime.Now.AddMilliseconds(10000));
         myLock.WriterLock.Unlock();
         Assert.Fail("Should throw an exception");
     }
     catch (ThreadInterruptedException)
     {
     }
 }
        [Test] public void AwaitUntilIsInterruptible([Values(true, false)] bool isFair)
        {
            _lock = new ReentrantLock(isFair);

            ICondition c = _lock.NewCondition();
            Thread     t = ThreadManager.StartAndAssertRegistered(
                "T1",
                () => Assert.Throws <ThreadInterruptedException>(
                    () => { using (_lock.Lock()) c.AwaitUntil(DateTime.UtcNow.AddMilliseconds(10000)); }));

            Thread.Sleep(Delays.Short);
            t.Interrupt();

            ThreadManager.JoinAndVerify();
        }