def test_patch_not_relevant_jsc(self): self.maxDiff = None mock_options = self._step_options() mock_options.group = "jsc" tool = MockTool(log_executive=True) tool.scm()._mockChangedFiles = [ "Tools/ChangeLog", "Tools/Scripts/webkitpy/tool/steps/steps_unittest.py" ] # FIXME: We shouldn't use a real port-object here, but there is too much to mock at the moment. tool._deprecated_port = DeprecatedPort() step = steps.CheckPatchRelevance(tool, mock_options) with self.assertRaises(ScriptError), OutputCapture( level=logging.INFO) as captured: step.run({}) self.assertEqual( captured.root.log.getvalue(), 'Checking relevance of patch\n', )
def test_archive_last_layout_test_results(self): tool = MockTool() reader = LayoutTestResultsReader(tool, "/var/logs") patch = tool.bugs.fetch_attachment(10001) tool.filesystem = MockFileSystem() # Should fail because the results_directory does not exist. expected_logs = "/mock-results does not exist, not archiving.\n" archive = OutputCapture().assert_outputs(self, reader.archive, [patch], expected_logs=expected_logs) self.assertEqual(archive, None) results_directory = "/mock-results" # Sanity check what we assume our mock results directory is. self.assertEqual(reader._results_directory(), results_directory) tool.filesystem.maybe_make_directory(results_directory) self.assertTrue(tool.filesystem.exists(results_directory)) self.assertNotEqual(reader.archive(patch), None) self.assertFalse(tool.filesystem.exists(results_directory))
def test_commit_info(self): command = AbstractRolloutPrepCommand() tool = MockTool() command.bind_to_tool(tool) output = OutputCapture() expected_logs = "Preparing rollout for bug 50000.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_logs=expected_logs) self.assertTrue(commit_info) mock_commit_info = Mock() mock_commit_info.bug_id = lambda: None tool._checkout.commit_info_for_revision = lambda revision: mock_commit_info expected_logs = "Unable to parse bug number from diff.\n" commit_info = output.assert_outputs(self, command._commit_info, [1234], expected_logs=expected_logs) self.assertEqual(commit_info, mock_commit_info)
def run_test(self, tests, expected_stdout, platform='test-win-xp', **args): options = MockOptions(all=False, csv=False, full=False, platform=platform, include_keyword=[], exclude_keyword=[], paths=False).update(**args) tool = MockTool() tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS command = PrintExpectations() command.bind_to_tool(tool) oc = OutputCapture() try: oc.capture_output() command.execute(options, tests, tool) finally: stdout, _, _ = oc.restore_output() self.assertMultiLineEqual(stdout, expected_stdout)
def test_mark_bug_fixed(self): tool = MockTool() tool._scm.last_svn_commit_log = lambda: "r9876 |" options = Mock() options.bug_id = 50000 options.comment = "MOCK comment" expected_logs = """Bug: <http://example.com/50000> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter. Revision: 9876 MOCK: user.open_url: http://example.com/50000 Is this correct? Adding comment to Bug 50000. MOCK bug comment: bug_id=50000, cc=None, see_also=None --- Begin comment --- MOCK comment Committed r9876: <https://trac.webkit.org/changeset/9876> --- End comment --- """ self.assert_execute_outputs(MarkBugFixed(), [], expected_logs=expected_logs, tool=tool, options=options)
def test_manual_reject_during_processing(self): queue = SecondThoughtsCommitQueue(MockTool()) queue.begin_work_queue() queue._tool.filesystem.write_text_file( '/tmp/layout-test-results/full_results.json', '' ) # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. queue._tool.filesystem.write_text_file( '/tmp/layout-test-results/webkit_unit_tests_output.xml', '') queue._options = Mock() queue._options.port = None expected_logs = """Running: webkit-patch --status-host=example.com clean --port=mac MOCK: update_status: commit-queue Cleaned working directory MOCK: update_status: commit-queue Error: commit-queue did not process patch. Reason: Patch is obsolete. MOCK: release_work_item: commit-queue 10000 """ self.maxDiff = None OutputCapture().assert_outputs(self, queue.process_work_item, [QueuesTest.mock_work_item], expected_logs=expected_logs)
def test_manual_reject_during_processing(self): queue = SecondThoughtsCommitQueue() queue.bind_to_tool(MockTool()) queue._tool.filesystem.write_text_file( '/mock/results.html', '' ) # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. queue._options = Mock() queue._options.port = None expected_stderr = """MOCK: update_status: commit-queue Cleaned working directory MOCK: update_status: commit-queue Updated working directory MOCK: update_status: commit-queue Applied patch MOCK: update_status: commit-queue Built patch MOCK: update_status: commit-queue Passed tests MOCK: update_status: commit-queue Retry MOCK: release_work_item: commit-queue 197 """ OutputCapture().assert_outputs(self, queue.process_work_item, [QueuesTest.mock_work_item], expected_stderr=expected_stderr)
def test_webkit_run_unit_tests(self): tool = MockTool(log_executive=True) tool._deprecated_port.run_python_unittests_command = lambda: None tool._deprecated_port.run_perl_unittests_command = lambda: None step = RunTests(tool, MockOptions(test=True, non_interactive=True, quiet=False, build_style="release", iterate_on_new_tests=0, group=None)) if sys.platform != "cygwin": expected_logs = """Running bindings generation tests MOCK run_and_throw_if_fail: ['mock-run-bindings-tests'], cwd=/mock-checkout Running run-webkit-tests MOCK run_and_throw_if_fail: ['mock-run-webkit-tests', '--no-new-test-results', '--no-show-results', '--exit-after-n-failures=30', '--quiet', '--skip-failing-tests'], cwd=/mock-checkout """ else: expected_logs = """Running bindings generation tests MOCK run_and_throw_if_fail: ['mock-run-bindings-tests'], cwd=/mock-checkout Running run-webkit-tests MOCK run_and_throw_if_fail: ['mock-run-webkit-tests', '--no-new-test-results', '--no-show-results', '--exit-after-n-failures=30', '--no-build'], cwd=/mock-checkout """ OutputCapture().assert_outputs(self, step.run, [{}], expected_logs=expected_logs)
def test_land(self): expected_logs = """Building WebKit Running Python unit tests Running Perl unit tests Running JavaScriptCore tests Running run-webkit-tests Committed r49824: <https://trac.webkit.org/changeset/49824> Updating bug 50000 """ mock_tool = MockTool() mock_tool.scm().create_patch = Mock(return_value="Patch1\nMockPatch\n") mock_tool.checkout().modified_changelogs = Mock(return_value=[]) self.assert_execute_outputs(Land(), [50000], options=self._default_options(), expected_logs=expected_logs, tool=mock_tool) # Make sure we're not calling expensive calls too often. self.assertEqual(mock_tool.scm().create_patch.call_count, 0) self.assertEqual(mock_tool.checkout().modified_changelogs.call_count, 1)
def _create_and_run_perfalizer(self, commands_to_fail=[]): tool = MockTool() patch = tool.bugs.fetch_attachment(10000) logs = [] def logger(message): logs.append(message) def run_webkit_patch(args): if args[0] in commands_to_fail: raise ScriptError def run_perf_test(build_path, description): self.assertTrue(description == 'without 10000' or description == 'with 10000') if 'run-perf-tests' in commands_to_fail: return -1 if 'results-page' not in commands_to_fail: tool.filesystem.write_text_file( tool.filesystem.join(build_path, 'PerformanceTestResults.html'), 'results page') return 0 perfalizer = PerfalizerTask(tool, patch, logger) perfalizer._port = TestPort(tool) perfalizer.run_webkit_patch = run_webkit_patch perfalizer._run_perf_test = run_perf_test capture = OutputCapture() capture.capture_output() if commands_to_fail: self.assertFalse(perfalizer.run()) else: self.assertTrue(perfalizer.run()) capture.restore_output() return logs
def test_report_flaky_tests(self): queue = TestCommitQueue(MockTool()) expected_stderr = """MOCK bug comment: bug_id=50002, cc=None --- Begin comment --- The commit-queue just saw foo/bar.html flake (Text diff mismatch) while processing attachment 10000 on bug 50000. Port: MockPort Platform: MockPlatform 1.0 --- End comment --- MOCK add_attachment_to_bug: bug_id=50002, description=Failure diff from bot filename=failure.diff MOCK bug comment: bug_id=50002, cc=None --- Begin comment --- The commit-queue just saw bar/baz.html flake (Text diff mismatch) while processing attachment 10000 on bug 50000. Port: MockPort Platform: MockPlatform 1.0 --- End comment --- MOCK add_attachment_to_bug: bug_id=50002, description=Archive of layout-test-results from bot filename=layout-test-results.zip MOCK bug comment: bug_id=50000, cc=None --- Begin comment --- The commit-queue encountered the following flaky tests while processing attachment 10000: foo/bar.html bug 50002 (author: [email protected]) bar/baz.html bug 50002 (author: [email protected]) The commit-queue is continuing to process your patch. --- End comment --- """ test_names = ["foo/bar.html", "bar/baz.html"] test_results = [self._mock_test_result(name) for name in test_names] class MockZipFile(object): def __init__(self): self.fp = StringIO() def read(self, path): return "" def namelist(self): # This is intentionally missing one diffs.txt to exercise the "upload the whole zip" codepath. return ['foo/bar-diffs.txt'] OutputCapture().assert_outputs(self, queue.report_flaky_tests, [QueuesTest.mock_work_item, test_results, MockZipFile()], expected_stderr=expected_stderr)
def test_rollout(self): tool = MockTool(log_executive=True) tool.filesystem.write_text_file( '/tmp/layout-test-results/full_results.json', '' ) # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. tool.filesystem.write_text_file( '/tmp/layout-test-results/webkit_unit_tests_output.xml', '') tool.buildbot.light_tree_on_fire() expected_stderr = { "begin_work_queue": self._default_begin_work_queue_stderr("commit-queue"), "next_work_item": "", "process_work_item": """MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'clean', '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Cleaned working directory MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'update', '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Updated working directory MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'apply-attachment', '--no-update', '--non-interactive', 10000, '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Applied patch MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'validate-changelog', '--non-interactive', 10000, '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue ChangeLog validated MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'build', '--no-clean', '--no-update', '--build-style=release', '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Built patch MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive', '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Passed tests MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'land-attachment', '--force-clean', '--non-interactive', '--parent-command=commit-queue', 10000, '--port=%(port_name)s'], cwd=/mock-checkout MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10000 """ % { "port_name": CommitQueue.port_name }, "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.' and additional comment 'Mock error message'\n", "handle_script_error": "ScriptError error message\n\nMOCK output\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, expected_stderr=expected_stderr)
def test_double_flaky_test_failure(self): commit_queue = MockCommitQueue([ None, None, None, None, ScriptError("MOCK test failure"), ScriptError("MOCK test failure again"), ]) # The (subtle) point of this test is that report_flaky_tests does not appear # in the expected_stderr for this run. # Note also that there is no attempt to run the tests w/o the patch. expected_stderr = """run_webkit_patch: ['clean'] command_passed: success_message='Cleaned working directory' patch='197' run_webkit_patch: ['update'] command_passed: success_message='Updated working directory' patch='197' run_webkit_patch: ['apply-attachment', '--no-update', '--non-interactive', 197] command_passed: success_message='Applied patch' patch='197' run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both'] command_passed: success_message='Built patch' patch='197' run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive'] command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure' patch='197' archive_last_layout_test_results: patch='197' run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive'] command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure again' patch='197' """ tool = MockTool(log_executive=True) patch = tool.bugs.fetch_attachment(197) task = CommitQueueTask(commit_queue, patch) self._double_flaky_test_counter = 0 def mock_failing_results_from_last_run(): CommitQueueTaskTest._double_flaky_test_counter += 1 if CommitQueueTaskTest._double_flaky_test_counter % 2: return [self._mock_test_result('foo.html')] return [self._mock_test_result('bar.html')] task._failing_results_from_last_run = mock_failing_results_from_last_run success = OutputCapture().assert_outputs( self, task.run, expected_stderr=expected_stderr) self.assertEqual(success, False)
def test_rebaseline_and_copy_test(self): command = RebaselineTest() tool = MockTool() command.bind_to_tool(tool) lion_port = tool.port_factory.get_from_builder_name("WebKit Mac10.7") tool.filesystem.write_text_file( os.path.join(lion_port.layout_tests_dir(), "userscripts/another-test-expected.txt"), "Dummy expected result") expected_logs = """Copying baseline from /mock-checkout/LayoutTests/userscripts/another-test-expected.txt to /mock-checkout/LayoutTests/platform/chromium-mac-snowleopard/userscripts/another-test-expected.txt. Retrieving http://example.com/f/builders/WebKit Mac10.7/results/layout-test-results/userscripts/another-test-actual.txt. """ OutputCapture().assert_outputs( self, command._rebaseline_test, [ "WebKit Mac10.7", "userscripts/another-test.html", ["chromium-mac-snowleopard"], "txt" ], expected_logs=expected_logs)
def test_can_build(self): # Needed to define port_name, used in AbstractEarlyWarningSystem.__init__ class TestEWS(AbstractEarlyWarningSystem): port_name = "win" # Needs to be a port which port/factory understands. queue = TestEWS() queue.bind_to_tool(MockTool(log_executive=True)) queue._options = MockOptions(port=None) expected_stderr = "MOCK run_and_throw_if_fail: ['echo', '--status-host=example.com', 'build', '--port=win', '--build-style=release', '--force-clean', '--no-update']\n" OutputCapture().assert_outputs(self, queue._can_build, [], expected_stderr=expected_stderr) def mock_run_webkit_patch(args): raise ScriptError("MOCK script error") queue.run_webkit_patch = mock_run_webkit_patch expected_stderr = "MOCK: update_status: None Unable to perform a build\n" OutputCapture().assert_outputs(self, queue._can_build, [], expected_stderr=expected_stderr)
def test_feeder_queue(self): self.maxDiff = None queue = TestFeederQueue() tool = MockTool(log_executive=True) expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("feeder-queue"), "process_work_item": """Warning, attachment 10001 on bug 50000 has invalid committer ([email protected]) Warning, attachment 10001 on bug 50000 has invalid committer ([email protected]) MOCK setting flag 'commit-queue' to '-' on attachment '10001' with comment 'Rejecting attachment 10001 from commit-queue.\n\[email protected] does not have committer permissions according to http://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/contributors.json. - If you do not have committer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags. - If you have committer rights please correct the error in Tools/Scripts/webkitpy/common/config/contributors.json by adding yourself to the file (no review needed). The commit-queue restarts itself every 2 hours. After restart the commit-queue will correctly respect your committer rights.' Feeding commit-queue high priority items [10005], regular items [10000] MOCK: update_work_items: commit-queue [10005, 10000] Feeding EWS (1 r? patch, 1 new) MOCK: submit_to_ews: 10002 """, "handle_unexpected_error": "Mock error message\n", } self.assert_queue_outputs(queue, tool=tool, expected_logs=expected_logs)
def test_overrides_are_included_correctly(self): command = RebaselineExpectations() tool = MockTool() command.bind_to_tool(tool) port = tool.port_factory.get('chromium-mac-lion') # This tests that the any tests marked as REBASELINE in the overrides are found, but # that the overrides do not get written into the main file. expectations_path = port.expectations_files()[0] expectations_contents = '' port._filesystem.write_text_file(expectations_path, expectations_contents) port.expectations_dict = lambda: { expectations_path: expectations_contents, 'overrides': ('BUGX REBASELINE : userscripts/another-test.html = TEXT\n' 'BUGY : userscripts/test.html = CRASH\n')} for path in port.expectations_files(): port._filesystem.write_text_file(path, '') port._filesystem.write_text_file(port.layout_tests_dir() + '/userscripts/another-test.html', '') self.assertEquals(command._tests_to_rebaseline(port), {'userscripts/another-test.html': set(['txt'])}) self.assertEquals(port._filesystem.read_text_file(expectations_path), expectations_contents)
def test_commit_queue(self): tool = MockTool() tool.filesystem.write_text_file('/tmp/layout-test-results/full_results.json', '') # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. tool.filesystem.write_text_file('/tmp/layout-test-results/webkit_unit_tests_output.xml', '') expected_stderr = { "begin_work_queue": self._default_begin_work_queue_stderr("commit-queue"), "next_work_item": "", "process_work_item": """MOCK: update_status: commit-queue Cleaned working directory MOCK: update_status: commit-queue Updated working directory MOCK: update_status: commit-queue Applied patch MOCK: update_status: commit-queue ChangeLog validated MOCK: update_status: commit-queue Built patch MOCK: update_status: commit-queue Passed tests MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10000 """, "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.' and additional comment 'Mock error message'\n", "handle_script_error": "ScriptError error message\n\nMOCK output\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, expected_stderr=expected_stderr)
def test_style_queue_with_watch_list_exception(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("style-queue"), "process_work_item": """Running: webkit-patch clean Running: webkit-patch update Running: webkit-patch apply-attachment --no-update --non-interactive 10000 Running: webkit-patch apply-watchlist-local 50000 Exception for ['echo', 'apply-watchlist-local', 50000] MOCK command output Running: webkit-patch check-style-local --non-interactive --quiet """, "handle_unexpected_error": "Mock error message\n", "handle_script_error": "MOCK output\n", } tool = MockTool( executive_throws_when_run=set(['apply-watchlist-local'])) self.assert_queue_outputs(StyleQueue(), expected_logs=expected_logs, tool=tool)
def test_update_command_non_interactive(self): tool = MockTool() options = MockOptions(non_interactive=True) step = Update(tool, options) self.assertEqual(["mock-update-webkit"], step._update_command()) tool._deprecated_port = ChromiumPort() self.assertEqual( ["Tools/Scripts/update-webkit", "--chromium", "--force-update"], step._update_command()) tool._deprecated_port = ChromiumXVFBPort() self.assertEqual( ["Tools/Scripts/update-webkit", "--chromium", "--force-update"], step._update_command()) tool._deprecated_port = ChromiumAndroidPort() self.assertEqual([ "Tools/Scripts/update-webkit", "--chromium", "--force-update", "--chromium-android" ], step._update_command())
def _run_and_expect_patch_analysis_result(self, commit_queue, expected_analysis_result, expected_reported_flaky_tests=[], expect_clean_tests_to_run=False, expected_failure_status_id=0): tool = MockTool(log_executive=True) patch = tool.bugs.fetch_attachment(10000) task = CommitQueueTask(commit_queue, patch) try: result = task.run() if result: analysis_result = PatchAnalysisResult.PASS else: analysis_result = PatchAnalysisResult.DEFER except ScriptError: analysis_result = PatchAnalysisResult.FAIL self.assertEqual(analysis_result, expected_analysis_result) self.assertEqual(commit_queue.get_reported_flaky_tests(), expected_reported_flaky_tests) self.assertEqual(commit_queue.did_run_clean_tests(), expect_clean_tests_to_run) # The failure status only means anything if we actually failed. if expected_analysis_result == PatchAnalysisResult.FAIL: self.assertEqual(task.failure_status_id, expected_failure_status_id)
def test_runtests_leopard_commit_queue_hack(self): mock_options = Mock() mock_options.non_interactive = True step = RunTests(MockTool(log_executive=True), mock_options) # FIXME: We shouldn't use a real port-object here, but there is too much to mock at the moment. mock_port = WebKitPort() mock_port.name = lambda: "Mac" mock_port.is_leopard = lambda: True step.port = lambda: mock_port expected_stderr = """Running Python unit tests MOCK run_and_throw_if_fail: ['WebKitTools/Scripts/test-webkitpy'] Running Perl unit tests MOCK run_and_throw_if_fail: ['WebKitTools/Scripts/test-webkitperl'] Running JavaScriptCore tests MOCK run_and_throw_if_fail: ['WebKitTools/Scripts/run-javascriptcore-tests'] Running run-webkit-tests MOCK run_and_throw_if_fail: ['WebKitTools/Scripts/run-webkit-tests', '--no-launch-safari', '--exit-after-n-failures=1', '--ignore-tests', 'compositing/iframes', '--quiet'] """ OutputCapture().assert_outputs(self, step.run, [{}], expected_stderr=expected_stderr)
def test_style_queue_with_style_exception(self): expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("style-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean MOCK: update_status: style-queue Cleaned working directory Running: webkit-patch --status-host=example.com update MOCK: update_status: style-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 MOCK: update_status: style-queue Applied patch Running: webkit-patch --status-host=example.com apply-watchlist-local 50000 MOCK: update_status: style-queue Watchlist applied Running: webkit-patch --status-host=example.com check-style-local --non-interactive --quiet MOCK: update_status: style-queue Style checked MOCK: update_status: style-queue Pass MOCK: release_work_item: style-queue 10000 """, "handle_unexpected_error": "Mock error message\n", "handle_script_error": "MOCK output\n", } tool = MockTool(executive_throws_when_run=set(['check-style'])) self.assert_queue_outputs(StyleQueue(), expected_logs=expected_logs, tool=tool)
def test_run(self): capture = OutputCapture() options = MockOptions(git_commit='MOCK git commit') files = { '/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png' } fs = MockFileSystem(files) scm = MockSCMDetector('git') step = AddSvnMimetypeForPng( MockTool(), options, MockSystemHost(os_name='linux', filesystem=fs), scm) state = { "changed_files": ["test.png", "test.txt"], } try: capture.assert_outputs(self, step.run, [state]) except SystemExit, e: self.assertEqual(e.code, 1)
def test_ensure_bug_url(self): capture = OutputCapture() step = PrepareChangeLog(MockTool(), MockOptions()) changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) changelog_path = "ChangeLog" state = { "bug_title": "Example title", "bug_id": 1234, "changelogs": [changelog_path], } step._tool.filesystem = MockFileSystem() step._tool.filesystem.write_text_file(changelog_path, changelog_contents) capture.assert_outputs(self, step._ensure_bug_url, [state]) actual_contents = step._tool.filesystem.read_text_file(changelog_path) expected_message = "Example title\n http://example.com/1234" expected_contents = changelog_contents.replace( "Need a short description (OOPS!).\n Need the bug URL (OOPS!).", expected_message) self.assertEqual(actual_contents, expected_contents)
def test_rebaseline_multiple_builders(self): old_exact_matches = builders._exact_matches try: builders._exact_matches = { "MOCK builder": {"port_name": "test-mac-leopard", "specifiers": set(["mock-specifier"])}, "MOCK builder2": {"port_name": "test-mac-snowleopard", "specifiers": set(["mock-specifier2"])}, } command = Rebaseline() tool = MockTool() command.bind_to_tool(tool) for port_name in tool.port_factory.all_port_names(): port = tool.port_factory.get(port_name) for path in port.expectations_files(): tool.filesystem.write_text_file(path, '') tool.executive = MockExecutive(should_log=True) def mock_builders_to_pull_from(): return [MockBuilder('MOCK builder'), MockBuilder('MOCK builder2')] def mock_tests_to_update(build): return ['mock/path/to/test.html'] command._builders_to_pull_from = mock_builders_to_pull_from command._tests_to_update = mock_tests_to_update expected_stdout = """rebaseline-json: {'mock/path/to/test.html': {'MOCK builder2': ['txt'], 'MOCK builder': ['txt']}} """ expected_stderr = """MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'txt', '--builder', 'MOCK builder2', '--test', 'mock/path/to/test.html'], cwd=/mock-checkout MOCK run_command: ['echo', 'rebaseline-test-internal', '--suffixes', 'txt', '--builder', 'MOCK builder', '--test', 'mock/path/to/test.html'], cwd=/mock-checkout MOCK run_command: ['echo', 'optimize-baselines', '--suffixes', 'txt', 'mock/path/to/test.html'], cwd=/mock-checkout """ OutputCapture().assert_outputs(self, command.execute, [MockOptions(optimize=True, builders=None, suffixes=["txt"], verbose=True), [], tool], expected_stdout=expected_stdout, expected_stderr=expected_stderr) finally: builders._exact_matches = old_exact_matches
def test_double_flaky_test_failure(self): commit_queue = FailingTestCommitQueue([ None, None, None, None, None, ScriptError("MOCK test failure"), ScriptError("MOCK test failure again"), ], [ "foo.html", "bar.html", "foo.html", ]) # The (subtle) point of this test is that report_flaky_tests does not appear # in the expected_logs for this run. # Note also that there is no attempt to run the tests w/o the patch. expected_logs = """run_webkit_patch: ['clean'] command_passed: success_message='Cleaned working directory' patch='10000' run_webkit_patch: ['update'] command_passed: success_message='Updated working directory' patch='10000' run_webkit_patch: ['apply-attachment', '--no-update', '--non-interactive', 10000] command_passed: success_message='Applied patch' patch='10000' run_webkit_patch: ['validate-changelog', '--check-oops', '--non-interactive', 10000] command_passed: success_message='ChangeLog validated' patch='10000' run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both'] command_passed: success_message='Built patch' patch='10000' run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive'] command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure' patch='10000' archive_last_test_results: patch='10000' run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive'] command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure again' patch='10000' """ tool = MockTool(log_executive=True) patch = tool.bugs.fetch_attachment(10000) task = CommitQueueTask(commit_queue, patch) success = OutputCapture().assert_outputs(self, task.run, expected_logs=expected_logs) self.assertFalse(success)
def test_rollout(self): tool = MockTool() tool.filesystem.write_text_file( '/tmp/layout-test-results/full_results.json', '' ) # Otherwise the commit-queue will hit a KeyError trying to read the results from the MockFileSystem. tool.filesystem.write_text_file( '/tmp/layout-test-results/webkit_unit_tests_output.xml', '') tool.buildbot.light_tree_on_fire() expected_logs = { "begin_work_queue": self._default_begin_work_queue_logs("commit-queue"), "process_work_item": """Running: webkit-patch --status-host=example.com clean --port=%(port)s MOCK: update_status: commit-queue Cleaned working directory Running: webkit-patch --status-host=example.com update --port=%(port)s MOCK: update_status: commit-queue Updated working directory Running: webkit-patch --status-host=example.com apply-attachment --no-update --non-interactive 10000 --port=%(port)s MOCK: update_status: commit-queue Applied patch Running: webkit-patch --status-host=example.com validate-changelog --check-oops --non-interactive 10000 --port=%(port)s MOCK: update_status: commit-queue ChangeLog validated Running: webkit-patch --status-host=example.com build --no-clean --no-update --build-style=release --port=%(port)s MOCK: update_status: commit-queue Built patch Running: webkit-patch --status-host=example.com build-and-test --no-clean --no-update --test --non-interactive --build-style=release --port=%(port)s MOCK: update_status: commit-queue Passed tests Running: webkit-patch --status-host=example.com land-attachment --force-clean --non-interactive --parent-command=commit-queue 10000 --port=%(port)s MOCK: update_status: commit-queue Landed patch MOCK: update_status: commit-queue Pass MOCK: release_work_item: commit-queue 10000 """ % { "port": "mac" }, "handle_script_error": "ScriptError error message\n\nMOCK output\n", "handle_unexpected_error": "MOCK setting flag 'commit-queue' to '-' on attachment '10000' with comment 'Rejecting attachment 10000 from commit-queue.\n\nMock error message'\n", } self.assert_queue_outputs(CommitQueue(), tool=tool, expected_logs=expected_logs)
def test_next_patch(self): queue = AbstractPatchQueue() tool = MockTool() queue.bind_to_tool(tool) queue._options = Mock() queue._options.port = None self.assertIsNone(queue._next_patch()) tool.status_server = MockStatusServer( work_items=[2, 10000, 10001, 10008]) expected_stdout = "MOCK: fetch_attachment: 2 is not a known attachment id\n" # A mock-only message to prevent us from making mistakes. expected_logs = """MOCK: update_status: None Skip MOCK: release_work_item: None 2 """ patch = OutputCapture().assert_outputs(self, queue._next_patch, expected_stdout=expected_stdout, expected_logs=expected_logs) # The patch.id() == 2 is ignored because it doesn't exist. self.assertEqual(patch.id(), 10000) self.assertEqual(queue._next_patch().id(), 10001) self.assertEqual(queue._next_patch().id(), 10008) self.assertEqual(queue._next_patch(), None) # When the queue is empty
def test_create_bug(self): create_bug = CreateBug() self.assertEquals("tom: Usage: create-bug BUG_TITLE", create_bug.execute("tom", [], None, None)) example_args = [ "sherrif-bot", "should", "have", "a", "create-bug", "command" ] tool = MockTool() # MockBugzilla has a create_bug, but it logs to stderr, this avoids any logging. tool.bugs.create_bug = lambda a, b, cc=None, assignee=None: 50004 self.assertEquals("tom: Created bug: http://example.com/50004", create_bug.execute("tom", example_args, tool, None)) def mock_create_bug(title, description, cc=None, assignee=None): raise Exception("Exception from bugzilla!") tool.bugs.create_bug = mock_create_bug self.assertEquals( "tom: Failed to create bug:\nException from bugzilla!", create_bug.execute("tom", example_args, tool, None))