Exemple #1
0
        public void AssertRun_Given_ClassWithNoAsyncDeadlock_Should_Succeed()
        {
            var instance = new ClassWithAsyncDeadlock();
            var finder   = new ConcurrencyChecker(instance, null, 2000);

            finder.Assert(1, () => instance.ShouldNotDeadLock());
        }
Exemple #2
0
        public void AssertRun_Given_ClassWithDictionaryAsyncDeadlock_Should_ThrowException()
        {
            var instance = new ClassWithAsyncDeadlock();
            var finder   = new ConcurrencyChecker(instance, null, 500);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(5, async() => await instance.DictionaryNotThreadSafeShouldLock()));

            Assert.AreEqual("Possible deadlock detected. Make sure that you do not use .Wait() or .Result on async methods.", error.Message);
        }
Exemple #3
0
        public void Run_Given_ClassWithObjectArrayConcurrencyIssues_With_ChangePropertyOnChildArray_Should_ThrowConcurrencyException()
        {
            var instance = new ClassWithObjectArrayConcurrencyIssues();

            var finder = new ConcurrencyChecker(instance, null, 2000, 2);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(2000, () => { instance.Names[0] = new { Name = "Jane" }; },
                                                                                 () => { instance.Names[0] = "Dave"; }));

            Console.WriteLine(error.Message);
        }
Exemple #4
0
        public void AssertRun_Given_ClassWithStaticFieldConcurrencyIssue_Should_ThrowException()
        {
            var instance = new ClassWithStaticFieldConcurrencyIssue();
            var finder   = new ConcurrencyChecker(instance);

            instance.ChangeNameTo("John");

            Assert.Throws <ConcurrencyException>(() => finder.Assert(5,
                                                                     () => instance.ChangeNameTo("Jane"),
                                                                     () => instance.ChangeNameTo("Peter")));
        }
Exemple #5
0
        public void Run_Given_ClassWithLevelThreeDepth_With_DepthAs1ConcurrencyIssues_Should_ThrowConcurrencyException()
        {
            var instance = new ClassWithLevelThreeDepth();

            var finder = new ConcurrencyChecker(instance, null, 2000, 1);

            finder.Assert(800, () =>
            {
                instance.ChildPropDepthOne.ChildProp.StringProp = "two";
            },
                          () => { instance.ChildPropDepthOne.ChildProp.StringProp = "three"; });
        }
Exemple #6
0
        public void Run_Given_ClassWithArrayConcurrencyIssues_With_ChangePropertyOnChildArray_Should_Succeed()
        {
            var instance = new ClassWithArrayConcurrencyIssues();

            var finder = new ConcurrencyChecker(instance, null, 2000);

            finder.Assert(600, () => { instance.Names[0] = "Jane"; },
                          () =>
            {
                var name = instance.Names[0];
            });
        }
Exemple #7
0
        public void Run_Given_ClassWithDictionaryConcurrencyIssues_With_AddChangePropertyOnChildDictionary_Should_Succeed()
        {
            var instance = new ClassWithDictionaryConcurrencyIssues();

            var finder = new ConcurrencyChecker(instance, null, 2000);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(2000, () => { instance.AddToCache(Guid.NewGuid().ToString(), 1); },
                                                                                 () => { Thread.Sleep(1); }));

            Console.WriteLine(error.Message);
            Assert.IsTrue(error.Message.Contains("ClassWithDictionaryConcurrencyIssues->Cache: Possible concurrency issue because of the following exception: Collection was modified; enumeration operation may not execute."));
        }
Exemple #8
0
        public void Run_Given_ClassWithDictionaryConcurrencyIssues_With_ChangePropertyOnChildDictionary_Should_ThrowConcurrencyException()
        {
            var instance = new ClassWithDictionaryConcurrencyIssues();

            var finder = new ConcurrencyChecker(instance, null, 2000);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(2000, () => { instance.UpdateCache("Existing", 1); },
                                                                                 () => { instance.UpdateCache("Existing", 2); }));

            Console.WriteLine(error.Message);
            Assert.IsTrue(error.Message.Contains("ClassWithDictionaryConcurrencyIssues->Cache: Possible concurrency issue because of the following exception: Collection was modified; enumeration operation may not execute."));
        }
Exemple #9
0
        public void Run_Given_ClassWithLevelThreeDepth_With_DepthAs3AndConcurrencyIssues_Should_ThrowConcurrencyException()
        {
            var instance = new ClassWithLevelThreeDepth();

            var finder = new ConcurrencyChecker(instance, null, 2000, 3);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(1500, () =>
            {
                instance.ChildPropDepthOne.ChildProp.StringProp = "two";
            },
                                                                                 () => { instance.ChildPropDepthOne.ChildProp.StringProp = "three"; }));

            Console.WriteLine(error.Message);
        }
Exemple #10
0
        public void Assert_Given_ClassWithTypeChangeConcurrencyIssue_With_ChangeType_Should_ThrowConcurrencyException()
        {
            var instance = new ClassWithTypeChangeConcurrencyIssue();

            var finder = new ConcurrencyChecker(instance, null, 2000000);

            var error = Assert.Throws <ConcurrencyException>(() => finder.Assert(10,
                                                                                 () => { instance.SetFoo(new ClassWithTypeChangeConcurrencyIssue.Foo1()); },
                                                                                 () => { instance.SetFoo(new ClassWithTypeChangeConcurrencyIssue.Foo2()); }));

            Console.WriteLine(error.Message);

            Assert.IsNotNull(error);
            Assert.IsTrue(error.Message.Contains(
                              "ClassWithTypeChangeConcurrencyIssue->_foo: Reference and actual number of value changes does not match."));
        }