Example #1
0
        [TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11
        public void IsTestFile_TimeoutIfConfigLocked()
        {
            // Arrange
            // We'll lock the file and sleep for long enough for the task to timeout
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task        = new IsTestFileByName();

            task.BuildEngine       = dummyEngine;
            task.FullFilePath      = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result;

            using (FileStream lockingStream = File.OpenWrite(configFile))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds + 600); // sleep for longer than the timeout period
                    lockingStream.Close();
                });

                result = task.Execute();
            }

            Assert.IsFalse(result, "Expecting the task to fail");

            dummyEngine.AssertMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString());
            dummyEngine.AssertNoWarnings();
            dummyEngine.AssertSingleErrorExists();
        }
Example #2
0
        [TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11
        public void IsTestFile_RetryIfConfigLocked()
        {
            // Arrange
            // We'll lock the file and sleep for long enough for the retry period to occur, but
            // not so long that the task times out
            int lockPeriodInMilliseconds = 1000;

            Assert.IsTrue(lockPeriodInMilliseconds < IsTestFileByName.MaxConfigRetryPeriodInMilliseconds, "Test setup error: the test is sleeping for too long");

            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task        = new IsTestFileByName();

            task.BuildEngine       = dummyEngine;
            task.FullFilePath      = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result;

            Stopwatch testDuration = Stopwatch.StartNew();

            using (FileStream lockingStream = File.OpenWrite(configFile))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(lockPeriodInMilliseconds);     // unlock the file after a short delay
                    lockingStream.Close();
                });

                result = task.Execute();
            }

            testDuration.Stop();
            Assert.IsTrue(testDuration.ElapsedMilliseconds > 1000, "Test error: expecting the test to have taken at least {0} milliseconds to run. Actual: {1}",
                          lockPeriodInMilliseconds, testDuration.ElapsedMilliseconds);

            Assert.IsTrue(result, "Expecting the task to succeed");
            Assert.IsTrue(task.IsTest, "Expecting the file to be recognised as a test");

            dummyEngine.AssertMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString());
            dummyEngine.AssertNoErrors();
            dummyEngine.AssertNoWarnings();
        }
Example #3
0
        private static bool ExecuteAndCheckSuccess(string analysisDir, string fullFileName)
        {
            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task        = new IsTestFileByName();

            task.BuildEngine       = dummyEngine;
            task.FullFilePath      = fullFileName;
            task.AnalysisConfigDir = analysisDir;

            bool taskSucess = task.Execute();

            Assert.IsTrue(taskSucess, "Expecting the task to succeed");
            dummyEngine.AssertNoErrors();
            dummyEngine.AssertNoWarnings();

            return(task.IsTest);
        }
Example #4
0
        private static bool ExecuteAndCheckSuccess(string analysisDir, string fullFileName)
        {
            var dummyEngine = new DummyBuildEngine();
            var task        = new IsTestFileByName
            {
                BuildEngine       = dummyEngine,
                FullFilePath      = fullFileName,
                AnalysisConfigDir = analysisDir
            };

            var taskSucess = task.Execute();

            taskSucess.Should().BeTrue("Expecting the task to succeed");
            dummyEngine.AssertNoErrors();
            dummyEngine.AssertNoWarnings();

            return(task.IsTest);
        }
        public void IsTestFile_InvalidRegexInConfig()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string invalidRegEx = "Invalid regex ((";
            EnsureAnalysisConfig(testFolder, invalidRegEx);

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task = new IsTestFileByName();
            task.BuildEngine = dummyEngine;
            task.FullFilePath = "Path";
            task.AnalysisConfigDir = testFolder;

            bool result = task.Execute();

            Assert.IsFalse(result, "Expecting the task to fail");
            dummyEngine.AssertSingleErrorExists(invalidRegEx); // expecting the invalid expression to appear in the error
        }
Example #6
0
        public void IsTestFile_InvalidRegexInConfig()
        {
            // Arrange
            string testFolder   = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string invalidRegEx = "Invalid regex ((";

            EnsureAnalysisConfig(testFolder, invalidRegEx);

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task        = new IsTestFileByName();

            task.BuildEngine       = dummyEngine;
            task.FullFilePath      = "Path";
            task.AnalysisConfigDir = testFolder;

            bool result = task.Execute();

            Assert.IsFalse(result, "Expecting the task to fail");
            dummyEngine.AssertSingleErrorExists(invalidRegEx); // expecting the invalid expression to appear in the error
        }
Example #7
0
        public void IsTestFile_InvalidRegexInConfig()
        {
            // Arrange
            var testFolder   = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
            var invalidRegEx = "Invalid regex ((";

            EnsureAnalysisConfig(testFolder, invalidRegEx);

            var dummyEngine = new DummyBuildEngine();
            var task        = new IsTestFileByName
            {
                BuildEngine       = dummyEngine,
                FullFilePath      = "Path",
                AnalysisConfigDir = testFolder
            };

            var result = task.Execute();

            result.Should().BeFalse("Expecting the task to fail");
            dummyEngine.AssertSingleErrorExists(invalidRegEx); // expecting the invalid expression to appear in the error
        }
        [TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11
        public void IsTestFile_TimeoutIfConfigLocked_TaskFails()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task        = new IsTestFileByName();

            task.BuildEngine       = dummyEngine;
            task.FullFilePath      = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result = true;

            TaskUtilitiesTests.PerformOpOnLockedFile(configFile, () => result = task.Execute(), shouldTimeoutReadingConfig: true);

            Assert.IsFalse(result, "Expecting the task to fail if the config file could not be read");
            dummyEngine.AssertNoWarnings();
            dummyEngine.AssertSingleErrorExists();
        }
Example #9
0
        [TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11
        public void IsTestFile_TimeoutIfConfigLocked_TaskFails()
        {
            // Arrange
            var testFolder = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);

            var configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            var dummyEngine = new DummyBuildEngine();
            var task        = new IsTestFileByName
            {
                BuildEngine       = dummyEngine,
                FullFilePath      = "XXX.proj",
                AnalysisConfigDir = testFolder
            };

            var result = true;

            TaskUtilitiesTests.PerformOpOnLockedFile(configFile, () => result = task.Execute(), shouldTimeoutReadingConfig: true);

            result.Should().BeFalse("Expecting the task to fail if the config file could not be read");
            dummyEngine.AssertNoWarnings();
            dummyEngine.AssertSingleErrorExists();
        }
        private static bool ExecuteAndCheckSuccess(string analysisDir, string fullFileName)
        {
            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task = new IsTestFileByName();
            task.BuildEngine = dummyEngine;
            task.FullFilePath = fullFileName;
            task.AnalysisConfigDir = analysisDir;

            bool taskSucess = task.Execute();
            Assert.IsTrue(taskSucess, "Expecting the task to succeed");
            dummyEngine.AssertNoErrors();
            dummyEngine.AssertNoWarnings();

            return task.IsTest;
        }
        [TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11
        public void IsTestFile_TimeoutIfConfigLocked_TaskFails()
        {
            // Arrange
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task = new IsTestFileByName();
            task.BuildEngine = dummyEngine;
            task.FullFilePath = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result = true;
            TaskUtilitiesTests.PerformOpOnLockedFile(configFile, () => result = task.Execute(), shouldTimeoutReadingConfig: true);

            Assert.IsFalse(result, "Expecting the task to fail if the config file could not be read");
            dummyEngine.AssertNoWarnings();
            dummyEngine.AssertSingleErrorExists();
        }
        public void IsTestFile_TimeoutIfConfigLocked()
        {
            // Arrange
            // We'll lock the file and sleep for long enough for the task to timeout
            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task = new IsTestFileByName();
            task.BuildEngine = dummyEngine;
            task.FullFilePath = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result;

            using (FileStream lockingStream = File.OpenWrite(configFile))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds + 600); // sleep for longer than the timeout period
                    lockingStream.Close();
                });

                result = task.Execute();
            }

            Assert.IsFalse(result, "Expecting the task to fail");

            dummyEngine.AssertSingleMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString());
            dummyEngine.AssertNoWarnings();
            dummyEngine.AssertSingleErrorExists();
        }
        public void IsTestFile_RetryIfConfigLocked()
        {
            // Arrange
            // We'll lock the file and sleep for long enough for the retry period to occur, but
            // not so long that the task times out
            int lockPeriodInMilliseconds = 1000;
            Assert.IsTrue(lockPeriodInMilliseconds < IsTestFileByName.MaxConfigRetryPeriodInMilliseconds, "Test setup error: the test is sleeping for too long");

            string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string configFile = EnsureAnalysisConfig(testFolder, ".XX.");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            IsTestFileByName task = new IsTestFileByName();
            task.BuildEngine = dummyEngine;
            task.FullFilePath = "XXX.proj";
            task.AnalysisConfigDir = testFolder;

            bool result;

            Stopwatch testDuration = Stopwatch.StartNew();

            using (FileStream lockingStream = File.OpenWrite(configFile))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        System.Threading.Thread.Sleep(lockPeriodInMilliseconds); // unlock the file after a short delay
                        lockingStream.Close();
                    });

                result = task.Execute();
            }

            testDuration.Stop();
            Assert.IsTrue(testDuration.ElapsedMilliseconds > 1000, "Test error: expecting the test to have taken at least {0} milliseconds to run. Actual: {1}",
                lockPeriodInMilliseconds, testDuration.ElapsedMilliseconds);

            Assert.IsTrue(result, "Expecting the task to succeed");
            Assert.IsTrue(task.IsTest, "Expecting the file to be recognised as a test");

            dummyEngine.AssertSingleMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString());
            dummyEngine.AssertNoErrors();
            dummyEngine.AssertNoWarnings();
        }