Example #1
0
        public void TestDebugFactoryRecursiveOptions()
        {
            DebugLockFactory <SimpleReadWriteLocking> factory = new DebugLockFactory <SimpleReadWriteLocking>(
                false, 0, 1, false, 1);

            using (ILockStrategy lck = factory.Create())
            {
                using (lck.Write())
                    using (lck.Write()) //second lock, allow recurse 1 time as per constructor
                    {
                        try { using (lck.Write()) { Assert.Fail(); } }
                        catch (Exception ex)
                        {
                            Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock
                        }
                    }

                using (lck.Read())
                    using (lck.Read()) //second lock, allow recurse 1 time as per constructor
                    {
                        try { using (lck.Read()) { Assert.Fail(); } }
                        catch (Exception ex)
                        {
                            Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock
                        }
                    }
            }
        }
Example #2
0
        public void TestDebugFactoryProperties()
        {
            DebugLockFactory <SimpleReadWriteLocking> factory = new DebugLockFactory <SimpleReadWriteLocking>(
                true, -1, 1, true, 1);

            Assert.AreEqual(true, factory.CaptureStack);
            factory.CaptureStack = false;
            Assert.AreEqual(false, factory.CaptureStack);

            Assert.AreEqual(true, factory.ConcurrentReads);
            factory.ConcurrentReads = false;
            Assert.AreEqual(false, factory.ConcurrentReads);

            Assert.AreEqual(-1, factory.LimitTimeout);
            factory.LimitTimeout = 1000;
            Assert.AreEqual(1000, factory.LimitTimeout);

            Assert.AreEqual(1, factory.LimitNestedReaders);
            factory.LimitNestedReaders = 10;
            Assert.AreEqual(10, factory.LimitNestedReaders);

            Assert.AreEqual(1, factory.LimitNestedWriters);
            factory.LimitNestedWriters = 5;
            Assert.AreEqual(5, factory.LimitNestedWriters);
        }
Example #3
0
        public void PreTestAsserts()
        {
            LockCounterFactory counters = LockFactory as LockCounterFactory;

            if (counters != null)
            {
                counters.GlobalAssertNoLocks();
                Assert.AreEqual(0, counters.CurrentReaderCount);
                Assert.AreEqual(0, counters.CurrentWriterCount);
            }
            DebugLockFactory debug = LockFactory as DebugLockFactory;

            if (debug != null)
            {
                debug.LocalAssertNoLocks();
                Assert.AreEqual(0, debug.LocalReaderCount);
                Assert.AreEqual(0, debug.LocalWriterCount);
                debug.LimitNestedReaders = 10;
                debug.LimitNestedWriters = 10;
            }
        }