Ejemplo n.º 1
0
        public void StartNonTerminatingProcessAndInterruptCurrentProcessShouldKillProcessButLeaveThreadRunning()
        {
            // ARRANGE
            Thread thread = new Thread(StartSleeperProcess);

            thread.Name = "sleeper thread";
            thread.Start();
            WaitForProcessToStart();

            // ACT
            ProcessExecutor.KillProcessCurrentlyRunningForProject("sleeper thread");

            // ASSERT
            // Sleeper runs for 60 seconds. We need to give up early and fail the test if it takes longer than 50.
            // If it runs for the full 60 seconds it will look the same as being interrupted, and the test will pass
            // incorrectly.
            Assert.IsTrue(thread.Join(TimeSpan.FromSeconds(50)), "Thread did not exit in reasonable time.");
            Assert.IsTrue(runnerThreadCompletedNormally, "Runner thread should have exited through normally.");
            // Ensure the external process was killed
            try
            {
                Assert.AreEqual(0, Process.GetProcessesByName("sleeper").Length);
            }
            catch (Exception)
            {
                Process.GetProcessesByName("sleeper")[0].Kill();
                Assert.Fail("Process was not killed.");
            }
        }