def test_junit_runner_timeout_fail(self): """When we set a timeout and force a failure, fail.""" with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(1) self.set_options(timeout_default=1) self.set_options(timeouts=True) with self.assertRaises(TaskError) as cm: self.execute_junit_runner( dedent(""" import org.junit.Test; import static org.junit.Assert.assertTrue; public class FooTest { @Test public void testFoo() { assertTrue(5 > 3); } } """)) self.assertEqual([t.name for t in cm.exception.failed_targets], ['foo_test']) # Ensures that Timeout is instantiated with a 1 second timeout. args, kwargs = mock_timeout.call_args self.assertEqual(args, (1, ))
def test_timeout_multiple_targets(self): target = self._create_node_module_target() test_target1 = self.make_target(spec='src/node/test_node_test:test1', target_type=NodeTestTarget, dependencies=[target], timeout=5) test_target2 = self.make_target(spec='src/node/test_node_test:test2', target_type=NodeTestTarget, dependencies=[target], timeout=5) task = self._resolve_node_module_and_create_tests_task( target, [test_target1, test_target2]) with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(5) with self.assertRaises(TestFailedTaskError) as cm: task.execute() # Verify that only the first target is in the failed_targets list, not all test targets. self.assertEqual(len(cm.exception.failed_targets), 1) self.assertEqual(cm.exception.failed_targets[0].address.spec, 'src/node/test_node_test:test1') # Ensures that Timeout is instantiated with a 5 second timeout. args, kwargs = mock_timeout.call_args self.assertEqual(args, (5, ))
def test_timeout(self): # Check that a failed timeout returns the right results. with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(1) self.run_failing_tests(targets=[self.sleep_timeout], failed_targets=[self.sleep_timeout]) # Ensures that Timeout is instantiated with a 1 second timeout. args, kwargs = mock_timeout.call_args self.assertEqual(args, (1, ))
def test_timeout(self): self.set_options(timeouts=True) task = self.create_task(self.context()) with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(1) with self.assertRaises(ErrorWhileTesting): task.execute() # Ensures that Timeout is instantiated with a 1 second timeout. args, kwargs = mock_timeout.call_args self.assertEqual(args, (1,))
def test_multiple_targets_single_target_timeout(self): with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(1) self.set_options(timeouts=True) task = self.create_task(self.context()) task.current_targets = [targetA] with self.assertRaises(ErrorWhileTesting) as cm: task.execute() self.assertEqual(len(cm.exception.failed_targets), 1) self.assertEqual(cm.exception.failed_targets[0].address.spec, 'TargetA') task.current_targets = [targetB] with self.assertRaises(ErrorWhileTesting) as cm: task.execute() self.assertEqual(len(cm.exception.failed_targets), 1) self.assertEqual(cm.exception.failed_targets[0].address.spec, 'TargetB')
def test_timeout(self): target = self._create_node_module_target() test_target = self.make_target(spec='src/node/test_node_test:test', target_type=NodeTestTarget, dependencies=[target], timeout=5) task = self._resolve_node_module_and_create_tests_task( target, [test_target]) with patch('pants.task.testrunner_task_mixin.Timeout') as mock_timeout: mock_timeout().__exit__.side_effect = TimeoutReached(5) with self.assertRaises(TestFailedTaskError): task.execute() # Ensures that Timeout is instantiated with a 5 second timeout. args, kwargs = mock_timeout.call_args self.assertEqual(args, (5, ))