Esempio n. 1
0
        public void TestAnalyzeProcNotFull()
        {
            AnalysisThread target     = CreateAnalysisThread(false);
            bool           eventFired = false;

            target.Complete += ((sender, args) => { eventFired = true; });
            target.AnalyzeProc();
            Assert.IsTrue(eventFired, "Analysation didnt fire the Complete event");
        }
Esempio n. 2
0
        public void ConstructorTest()
        {
            bool           isFull = true;
            AnalysisThread target = CreateAnalysisThread(isFull);

            Assert.IsNotNull(target, "Constructor is broken");

            PrivateObject privateAnalysis = new PrivateObject(target, new PrivateType(typeof(AnalysisThread)));

            Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("projects"), "Constructor did not set the projects.");
            Assert.IsTrue((bool)privateAnalysis.GetFieldOrProperty("full"), "Constructor did not set the full flag.");
            Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("core"), "Constructor did not set the core.");
        }
Esempio n. 3
0
        private static AnalysisThread CreateAnalysisThread(bool isFull)
        {
            StyleCopCore       core            = new StyleCopCore();
            List <CodeProject> projects        = new List <CodeProject>();
            Mock <CodeProject> mockCodeProject = new Mock <CodeProject>();
            CodeProject        codeProject     = new CodeProject(0, "test", new Configuration(new string[0]));

            projects.Add(codeProject);

            AnalysisThread target = new AnalysisThread(isFull, projects, core);

            return(target);
        }
Esempio n. 4
0
        private static AnalysisThread CreateAnalysisThread(bool isFull)
        {
            var core            = new StyleCopCore();
            var projects        = new List <CodeProject>();
            var mockCodeProject = new Mock <CodeProject>(MockBehavior.Strict);
            var codeProject     = new CodeProject(0, "test", new Configuration(new string[0]));

            projects.Add(codeProject);

            var target = new AnalysisThread(isFull, projects, core);

            return(target);
        }
        public void TestAnalyzeProcNotFull()
        {
            try
            {
                AnalysisThread target     = CreateAnalysisThread(false);
                bool           eventFired = false;

                target.Complete += ((sender, args) => { eventFired = true; });
                target.AnalyzeProc();
                Assert.IsTrue(eventFired, "Analysation didnt fire the Complete event");
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }
        }
        public void ConstructorTest()
        {
            try
            {
                bool           isFull = true;
                AnalysisThread target = CreateAnalysisThread(isFull);
                Assert.IsNotNull(target, "Constructor is broken");

                PrivateObject privateAnalysis = new PrivateObject(target, new PrivateType(typeof(AnalysisThread)));
                Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("projects"), "Constructor did not set the projects.");
                Assert.IsTrue((bool)privateAnalysis.GetFieldOrProperty("full"), "Constructor did not set the full flag.");
                Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("core"), "Constructor did not set the core.");
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 7
0
 private IEnumerable <AnalysisThread> GetThreadDetails()
 {
     foreach (var thread in Runtime.Threads)
     {
         var at = new AnalysisThread(thread)
         {
             Address         = thread.Address,
             LockCount       = thread.LockCount,
             ManagedThreadId = thread.ManagedThreadId,
             OSThreadId      = thread.OSThreadId,
             StackBase       = thread.StackBase,
             StackLimit      = thread.StackBase
         };
         at.SetApartment();
         at.SetException();
         at.SetFinalizer();
         at.SetGCMode();
         yield return(at);
     }
 }
        private static AnalysisThread CreateAnalysisThread(bool isFull)
        {
            AnalysisThread target = null;

            try
            {
                StyleCopCore       core            = new StyleCopCore();
                List <CodeProject> projects        = new List <CodeProject>();
                Mock <CodeProject> mockCodeProject = new Mock <CodeProject>();
                CodeProject        codeProject     = new CodeProject(0, "test", new Configuration(new string[0]));
                projects.Add(codeProject);

                target = new AnalysisThread(isFull, projects, core);
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }

            return(target);
        }
        public void CheckRandomData(Random random, Analyzer a, int iterations, int maxWordLength, bool simple, bool offsetsAreCorrect)
        {
            CheckResetException(a, "best effort");
            long seed = random.Next();
            bool useCharFilter = random.NextBoolean();
            Directory dir = null;
            RandomIndexWriter iw = null;
            string postingsFormat = TestUtil.GetPostingsFormat("dummy");
            bool codecOk = iterations * maxWordLength < 100000
                || !(postingsFormat.Equals("Memory") || postingsFormat.Equals("SimpleText"));
            if (Rarely(random) && codecOk)
            {
                dir = NewFSDirectory(CreateTempDir("bttc"));
                iw = new RandomIndexWriter(new Random((int)seed), dir, a, ClassEnvRule.Similarity, ClassEnvRule.TimeZone);
            }

            bool success = false;
            try
            {
                CheckRandomData(new Random((int)seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
                // now test with multiple threads: note we do the EXACT same thing we did before in each thread,
                // so this should only really fail from another thread if its an actual thread problem
                int numThreads = TestUtil.NextInt(random, 2, 4);
                var startingGun = new CountdownEvent(1);
                var threads = new AnalysisThread[numThreads];
                for (int i = 0; i < threads.Length; i++)
                {
                    threads[i] = new AnalysisThread(seed, /*startingGun,*/ a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw, this);
                }
                
                Array.ForEach(threads, thread => thread.Start());                

                startingGun.Signal();
                
                foreach (var t in threads)
                {
                    try
                    {
                        t.Join();
                    }
                    catch (ThreadInterruptedException e)
                    {
                        Fail("Thread interrupted");
                    }
                }

                if (threads.Any(x => x.Failed))
                    Fail("Thread interrupted");

                success = true;
            }
            finally
            {
                if (success)
                {
                    IOUtils.Close(iw, dir);
                }
                else
                {
                    IOUtils.CloseWhileHandlingException(iw, dir); // checkindex
                }
            }
        }
Esempio n. 10
0
        public static void CheckRandomData(Random random, Analyzer a, int iterations, int maxWordLength, bool simple, bool offsetsAreCorrect)
        {
            CheckResetException(a, "best effort");
            long              seed           = random.Next();
            bool              useCharFilter  = random.NextBoolean();
            Directory         dir            = null;
            RandomIndexWriter iw             = null;
            string            postingsFormat = TestUtil.GetPostingsFormat("dummy");
            bool              codecOk        = iterations * maxWordLength < 100000 ||
                                               !(postingsFormat.Equals("Memory") || postingsFormat.Equals("SimpleText"));

            if (Rarely(random) && codecOk)
            {
                dir = NewFSDirectory(CreateTempDir("bttc"));
                iw  = new RandomIndexWriter(new Random((int)seed), dir, a);
            }

            bool success = false;

            try
            {
                CheckRandomData(new Random((int)seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
                // now test with multiple threads: note we do the EXACT same thing we did before in each thread,
                // so this should only really fail from another thread if its an actual thread problem
                int numThreads  = TestUtil.NextInt(random, 2, 4);
                var startingGun = new CountDownLatch(1);
                var threads     = new AnalysisThread[numThreads];
                for (int i = 0; i < threads.Length; i++)
                {
                    threads[i] = new AnalysisThread(seed, /*startingGun,*/ a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
                }

                Array.ForEach(threads, thread => thread.Start());

                startingGun.countDown();

                foreach (var t in threads)
                {
                    try
                    {
                        t.Join();
                    }
                    catch (ThreadInterruptedException e)
                    {
                        Fail("Thread interrupted");
                    }
                }

                if (threads.Any(x => x.Failed))
                {
                    Fail("Thread interrupted");
                }

                success = true;
            }
            finally
            {
                if (success)
                {
                    IOUtils.Close(iw, dir);
                }
                else
                {
                    IOUtils.CloseWhileHandlingException(iw, dir); // checkindex
                }
            }
        }