private void DoRunCancelingTests(bool killProcesses, int lower) { MockOptions.Setup(o => o.KillProcessesOnCancel).Returns(killProcesses); List <Model.TestCase> testCasesToRun = TestDataCreator.GetTestCases("Crashing.LongRunning", "LongRunningTests.Test2"); testCasesToRun.Should().HaveCount(2); var stopwatch = new Stopwatch(); var executor = new TestExecutor(TestEnvironment.Logger, TestEnvironment.Options, MockDebuggerAttacher.Object); var canceller = new Thread(() => { Thread.Sleep(WaitBeforeCancelInMs); executor.Cancel(); }); canceller.Start(); stopwatch.Start(); executor.RunTests(testCasesToRun.Select(tc => tc.ToVsTestCase()), MockRunContext.Object, MockFrameworkHandle.Object); stopwatch.Stop(); canceller.Join(); stopwatch.ElapsedMilliseconds.Should().BeInRange(lower, lower + OverheadInMs); }
public void RunTests_CancelingExecutor_StopsTestExecution() { List<Model.TestCase> testCasesToRun = TestDataCreator.GetTestCasesOfSampleTests("Crashing.LongRunning", "LongRunningTests.Test3"); Stopwatch stopwatch = new Stopwatch(); TestExecutor executor = new TestExecutor(TestEnvironment); Thread thread = new Thread(() => executor.RunTests(testCasesToRun.Select(DataConversionExtensions.ToVsTestCase), MockRunContext.Object, MockFrameworkHandle.Object)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); executor.Cancel(); thread.Join(); stopwatch.Stop(); stopwatch.ElapsedMilliseconds.Should().BeInRange(3000, // 1st test should be executed 4000); // 2nd test should not be executed }
public void RunTests_CancelingExecutor_StopsTestExecution() { List <Model.TestCase> testCasesToRun = TestDataCreator.GetTestCasesOfSampleTests("Crashing.LongRunning", "LongRunningTests.Test3"); Stopwatch stopwatch = new Stopwatch(); TestExecutor executor = new TestExecutor(TestEnvironment); Thread thread = new Thread(() => executor.RunTests(testCasesToRun.Select(DataConversionExtensions.ToVsTestCase), MockRunContext.Object, MockFrameworkHandle.Object)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); executor.Cancel(); thread.Join(); stopwatch.Stop(); stopwatch.ElapsedMilliseconds.Should().BeInRange(3000, // 1st test should be executed 4000); // 2nd test should not be executed }