Ejemplo n.º 1
0
 def test_wait_for_try_jobs_done(self):
     host = MockHost()
     host.executive = MockExecutive(output='lgtm')
     git_cl = GitCL(host)
     git_cl.fetch_raw_try_job_results = lambda **_: [
         {
             'builder_name': 'some-builder',
             'status': 'COMPLETED',
             'result': 'FAILURE',
             'tags': [
                 'build_address:luci.chromium.try/chromium_presubmit/100',
             ],
             'url': 'http://ci.chromium.org/b/8931586523737389552',
         },
     ]
     self.assertEqual(
         git_cl.wait_for_try_jobs(),
         CLStatus(
             status='lgtm',
             try_job_results={
                 Build('some-builder', 100): TryJobStatus('COMPLETED', 'FAILURE'),
             }
         )
     )
     self.assertEqual(
         host.stdout.getvalue(),
         'Waiting for try jobs, timeout: 7200 seconds.\n')
Ejemplo n.º 2
0
 def test_wait_for_try_jobs_done(self):
     host = MockHost()
     host.executive = MockExecutive(output='lgtm')
     git_cl = GitCL(host)
     git_cl._host.web = MockWeb(responses=[{
         'status_code':
         200,
         'body':
         SEARCHBUILDS_RESPONSE_PREFIX + b"""{
                 "builds": [
                     {
                         "status": "FAILURE",
                         "builder": {
                             "builder": "some-builder"
                         },
                         "number": 100
                     }
                 ]
             }"""
     }])
     self.assertEqual(
         git_cl.wait_for_try_jobs(),
         CLStatus(status='lgtm',
                  try_job_results={
                      Build('some-builder', 100):
                      TryJobStatus('COMPLETED', 'FAILURE'),
                  }))
     self.assertEqual(host.stdout.getvalue(),
                      'Waiting for try jobs, timeout: 7200 seconds.\n')
Ejemplo n.º 3
0
    def test_exportable_commits_since_not_require_clean(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'diff-tree':
            'third_party/WebKit/LayoutTests/external/wpt/some_files',
            'footers':
            'cr-rev-position',
            'format-patch':
            'hey I\'m a patch',
            'rev-list':
            'add087a97844f4b9e307d9a216940582d96db306\n'
            'add087a97844f4b9e307d9a216940582d96db307\n'
            'add087a97844f4b9e307d9a216940582d96db308\n'
        })
        local_wpt = MockLocalWPT(test_patch=[
            (True, ''),
            (False, 'patch failure'),
            (True, ''),
        ])

        commits, _ = _exportable_commits_since('beefcafe',
                                               host,
                                               local_wpt,
                                               MockWPTGitHub(pull_requests=[]),
                                               require_clean=False)
        self.assertEqual(len(commits), 3)
Ejemplo n.º 4
0
 def test_run(self):
     host = MockHost()
     host.executive = MockExecutive(output='mock-output')
     git_cl = GitCL(host)
     output = git_cl.run(['command'])
     self.assertEqual(output, 'mock-output')
     self.assertEqual(host.executive.calls, [['git', 'cl', 'command']])
Ejemplo n.º 5
0
    def test_start_cmd(self):
        # Fails on win - see https://bugs.webkit.org/show_bug.cgi?id=84726
        if sys.platform == 'win32':
            return

        def fake_pid(_):
            host.filesystem.write_text_file('/tmp/WebKit/httpd.pid', '42')
            return True

        host = MockHost()
        host.executive = MockExecutive(should_log=True)
        test_port = test.TestPort(host)
        host.filesystem.write_text_file(test_port.path_to_apache_config_file(),
                                        '')

        server = ApacheHTTP(test_port,
                            '/mock/output_dir',
                            additional_dirs=[],
                            number_of_servers=4)
        server._check_that_all_ports_are_available = lambda: True
        server._is_server_running_on_all_ports = lambda: True
        server._wait_for_action = fake_pid
        oc = OutputCapture()
        try:
            oc.capture_output()
            server.start()
            server.stop()
        finally:
            _, _, logs = oc.restore_output()
        self.assertIn('StartServers 4', logs)
        self.assertIn('MinSpareServers 4', logs)
        self.assertIn('MaxSpareServers 4', logs)
Ejemplo n.º 6
0
 def test_wait_for_try_jobs_cl_closed(self):
     host = MockHost()
     host.executive = MockExecutive(output='closed')
     git_cl = GitCL(host)
     git_cl._host.web = MockWeb(responses=[{
         'status_code':
         200,
         'body':
         SEARCHBUILDS_RESPONSE_PREFIX + b"""{
                 "builds": [
                     {
                         "status": "STARTED",
                         "builder": {
                             "builder": "some-builder"
                         }
                     }
                 ]
             }"""
     }])
     self.assertEqual(
         git_cl.wait_for_try_jobs(),
         CLStatus(
             status='closed',
             try_job_results={
                 Build('some-builder', None): TryJobStatus('STARTED', None),
             },
         ))
     self.assertEqual(host.stdout.getvalue(),
                      'Waiting for try jobs, timeout: 7200 seconds.\n')
Ejemplo n.º 7
0
    def test_ensure_manifest_raises_exception(self):
        host = MockHost()
        host.executive = MockExecutive(should_throw=True)
        port = TestPort(host)

        with self.assertRaises(ScriptError):
            WPTManifest.ensure_manifest(port)
    def test_exportable_commits_since(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'show': 'fake message',
            'rev-list': 'add087a97844f4b9e307d9a216940582d96db306',
            'rev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
            'crrev-parse': 'add087a97844f4b9e307d9a216940582d96db306',
            'diff': 'fake diff',
            'diff-tree': 'third_party/WebKit/LayoutTests/external/wpt/some\n'
                         'third_party/WebKit/LayoutTests/external/wpt/files',
            'format-patch': 'hey I\'m a patch',
            'footers': 'cr-rev-position',
        }, strict=True)

        commits, _ = _exportable_commits_since(
            'beefcafe', host, MockLocalWPT(test_patch=[(True, '')]), MockWPTGitHub(pull_requests=[]))
        self.assertEqual(len(commits), 1)
        self.assertIsInstance(commits[0], ChromiumCommit)
        self.assertEqual(host.executive.calls, [
            ['git', 'rev-parse', '--show-toplevel'],
            ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--',
             'add087a97844f4b9e307d9a216940582d96db306/third_party/WebKit/LayoutTests/external/wpt/'],
            ['git', 'footers', '--position', 'add087a97844f4b9e307d9a216940582d96db306'],
            ['git', 'show', '--format=%B', '--no-patch', 'add087a97844f4b9e307d9a216940582d96db306'],
            ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'add087a97844f4b9e307d9a216940582d96db306', '--',
             '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'],
            ['git', 'format-patch', '-1', '--stdout', 'add087a97844f4b9e307d9a216940582d96db306', '--',
             'third_party/WebKit/LayoutTests/external/wpt/some', 'third_party/WebKit/LayoutTests/external/wpt/files'],
        ])
Ejemplo n.º 9
0
 def test_run_with_auth(self):
     host = MockHost()
     host.executive = MockExecutive(output='mock-output')
     git_cl = GitCL(host, auth_refresh_token_json='token.json')
     git_cl.run(['try', '-b', 'win10_blink_rel'])
     self.assertEqual(
         host.executive.calls,
         [['git', 'cl', 'try', '-b', 'win10_blink_rel', '--auth-refresh-token-json', 'token.json']])
Ejemplo n.º 10
0
 def test_cl_description_moves_noexport_tag(self):
     host = MockHost()
     host.executive = MockExecutive(output='Summary\n\nNo-Export: true\n\n')
     importer = TestImporter(host)
     description = importer._cl_description(directory_owners={})
     self.assertIn(
         'No-Export: true',
         description)
Ejemplo n.º 11
0
    def test_derives_sha_from_position(self):
        host = MockHost()
        host.executive = MockExecutive(output='c881563d734a86f7d9cd57ac509653a61c45c240')
        pos = 'Cr-Commit-Position: refs/heads/master@{#789}'
        chromium_commit = ChromiumCommit(host, position=pos)

        self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
    def test_check_is_functional_cdb_not_found(self):
        host = MockHost()
        host.executive = MockExecutive(should_throw=True)

        build_dir = "/mock-checkout/out/Debug"
        host.filesystem.maybe_make_directory(build_dir)
        dump_reader = DumpReaderWin(host, build_dir)

        self.assertFalse(dump_reader.check_is_functional())
Ejemplo n.º 13
0
 def test_wait_for_closed_status_closed(self):
     host = MockHost()
     host.executive = MockExecutive(output='closed')
     git_cl = GitCL(host)
     self.assertEqual(git_cl.wait_for_closed_status(), 'closed')
     self.assertEqual(
         host.stdout.getvalue(),
         'Waiting for closed status, timeout: 1800 seconds.\n'
         'CL is closed.\n')
Ejemplo n.º 14
0
    def test_derives_position_from_sha(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'footers': 'refs/heads/master@{#789}'
        })
        chromium_commit = ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240')

        self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
Ejemplo n.º 15
0
    def test_is_commit_affecting_directory(self):
        host = MockHost()
        # return_exit_code=True is passed to run() in the method under test,
        # so the mock return value should be exit code instead of output.
        host.executive = mock_git_commands({'diff-tree': 1}, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.is_commit_affecting_directory('HEAD', 'css/'))
        self.assertEqual(host.executive.calls, [['git', 'diff-tree', '--quiet', '--no-commit-id', 'HEAD', '--', 'css/']])
Ejemplo n.º 16
0
    def test_commits_in_range(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'rev-list': '34ab6c3f5aee8bf05207b674edbcb6affb179545 Fix presubmit errors\n'
                        '8c596b820634a623dfd7a2b0f36007ce2f7a0c9f test\n'
        }, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertTrue(local_wpt.commits_in_range('HEAD~2', 'HEAD'))
        self.assertEqual(host.executive.calls, [['git', 'rev-list', '--pretty=oneline', 'HEAD~2..HEAD']])
Ejemplo n.º 17
0
    def test_test_patch_error(self):
        def _run_fn(args):
            if args[0] == 'git' and args[1] == 'apply':
                raise ScriptError('MOCK failed applying patch')
            return ''

        host = MockHost()
        host.executive = MockExecutive(run_command_fn=_run_fn)
        local_wpt = LocalWPT(host, 'token')

        self.assertEqual(local_wpt.test_patch('dummy patch'), (False, 'MOCK failed applying patch'))
Ejemplo n.º 18
0
    def test_when_commit_has_no_position(self):
        host = MockHost()

        def run_command(_):
            raise ScriptError('Unable to infer commit position from footers rutabaga')

        host.executive = MockExecutive(run_command_fn=run_command)
        chromium_commit = ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240')

        self.assertEqual(chromium_commit.position, 'no-commit-position-yet')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
Ejemplo n.º 19
0
 def test_cl_description_with_environ_variables(self):
     host = MockHost()
     host.executive = MockExecutive(output='Last commit message\n')
     importer = TestImporter(host)
     importer.host.environ['BUILDBOT_MASTERNAME'] = 'my.master'
     importer.host.environ['BUILDBOT_BUILDERNAME'] = 'b'
     importer.host.environ['BUILDBOT_BUILDNUMBER'] = '123'
     description = importer._cl_description(directory_owners={})
     self.assertIn(
         'Build: https://ci.chromium.org/buildbot/my.master/b/123\n\n',
         description)
     self.assertEqual(host.executive.calls, [['git', 'log', '-1', '--format=%B']])
Ejemplo n.º 20
0
    def test_get_build_results(self):
        host = MockHost()
        host.executive = MockExecutive(output='{"number": 422, "id": "abcd"}')

        bb_agent = BBAgent(host)
        build = bb_agent.get_latest_finished_build('linux-blink-rel')
        self.assertEqual(build, Build('linux-blink-rel', 422, 'abcd'))
        bb_agent.get_build_test_results(build, 'blink_web_tests')
        self.assertEqual(host.executive.calls[-1], [
            bb_agent.bb_bin_path, 'log', '-nocolor', build.build_id,
            'blink_web_tests', 'json.output'
        ])
Ejemplo n.º 21
0
    def test_test_patch_empty_diff(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'apply': '',
            'add': '',
            'diff': '',
            'reset': '',
            'clean': '',
            'checkout': '',
        }, strict=True)
        local_wpt = LocalWPT(host, 'token')

        self.assertEqual(local_wpt.test_patch('dummy patch'), (False, ''))
Ejemplo n.º 22
0
 def test_cl_description_with_empty_environ(self):
     host = MockHost()
     host.executive = MockExecutive(output='Last commit message\n\n')
     importer = TestImporter(host)
     description = importer._cl_description(directory_owners={})
     self.assertEqual(
         description, 'Last commit message\n\n'
         'Note to sheriffs: This CL imports external tests and adds\n'
         'expectations for those tests; if this CL is large and causes\n'
         'a few new failures, please fix the failures by adding new\n'
         'lines to TestExpectations rather than reverting. See:\n'
         'https://chromium.googlesource.com'
         '/chromium/src/+/master/docs/testing/web_platform_tests.md\n\n'
         'No-Export: true')
     self.assertEqual(host.executive.calls,
                      [['git', 'log', '-1', '--format=%B']])
Ejemplo n.º 23
0
 def test_cl_description_with_directory_owners(self):
     host = MockHost()
     host.executive = MockExecutive(output='Last commit message\n\n')
     importer = TestImporter(host)
     description = importer._cl_description(directory_owners={
         ('*****@*****.**',): ['external/wpt/foo', 'external/wpt/bar'],
         ('*****@*****.**', '*****@*****.**'): ['external/wpt/baz'],
     })
     self.assertIn(
         'Directory owners for changes in this CL:\n'
         '[email protected]:\n'
         '  external/wpt/foo\n'
         '  external/wpt/bar\n'
         '[email protected], [email protected]:\n'
         '  external/wpt/baz\n\n',
         description)
Ejemplo n.º 24
0
 def test_wait_for_closed_status_timeout(self):
     host = MockHost()
     host.executive = MockExecutive(output='commit')
     git_cl = GitCL(host)
     self.assertIsNone(git_cl.wait_for_closed_status())
     self.assertEqual(
         host.stdout.getvalue(),
         'Waiting for closed status, timeout: 1800 seconds.\n'
         'Waiting for closed status. 120 seconds passed.\n'
         'Waiting for closed status. 360 seconds passed.\n'
         'Waiting for closed status. 600 seconds passed.\n'
         'Waiting for closed status. 840 seconds passed.\n'
         'Waiting for closed status. 1080 seconds passed.\n'
         'Waiting for closed status. 1320 seconds passed.\n'
         'Waiting for closed status. 1560 seconds passed.\n'
         'Waiting for closed status. 1800 seconds passed.\n'
         'Timed out waiting for closed status.\n')
Ejemplo n.º 25
0
    def test_fetch_current_revision_commit(self):
        host = MockHost()
        host.executive = mock_git_commands(
            {
                'fetch': '',
                'rev-parse': '4de71d0ce799af441c1f106c5432c7fa7256be45',
                'footers': 'no-commit-position-yet'
            },
            strict=True)
        data = {
            'change_id': 'Ib58c7125d85d2fd71af711ea8bbd2dc927ed02cb',
            'subject': 'fake subject',
            '_number': 638250,
            'current_revision': '1',
            'revisions': {
                '1': {
                    'fetch': {
                        'http': {
                            'url':
                            'https://chromium.googlesource.com/chromium/src',
                            'ref': 'refs/changes/50/638250/1'
                        }
                    }
                }
            },
            'owner': {
                'email': '*****@*****.**'
            },
        }
        gerrit_cl = GerritCL(data, MockGerritAPI())
        commit = gerrit_cl.fetch_current_revision_commit(host)

        self.assertEqual(commit.sha,
                         '4de71d0ce799af441c1f106c5432c7fa7256be45')
        self.assertEqual(host.executive.calls,
                         [[
                             'git', 'fetch',
                             'https://chromium.googlesource.com/chromium/src',
                             'refs/changes/50/638250/1'
                         ], ['git', 'rev-parse', 'FETCH_HEAD'],
                          [
                              'git', 'footers', '--position',
                              '4de71d0ce799af441c1f106c5432c7fa7256be45'
                          ]])
Ejemplo n.º 26
0
    def test_filtered_changed_files_blacklist(self):
        host = MockHost()

        fake_files = ['file1', 'MANIFEST.json', 'file3', 'OWNERS']
        qualified_fake_files = [CHROMIUM_WPT_DIR + f for f in fake_files]

        host.executive = mock_git_commands({
            'diff-tree': '\n'.join(qualified_fake_files),
            'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240',
        })

        position_footer = 'Cr-Commit-Position: refs/heads/master@{#789}'
        chromium_commit = ChromiumCommit(host, position=position_footer)

        files = chromium_commit.filtered_changed_files()

        expected_files = ['file1', 'file3']
        qualified_expected_files = [CHROMIUM_WPT_DIR + f for f in expected_files]

        self.assertEqual(files, qualified_expected_files)
Ejemplo n.º 27
0
 def test_wait_for_try_jobs_cl_closed(self):
     host = MockHost()
     host.executive = MockExecutive(output='closed')
     git_cl = GitCL(host)
     git_cl.fetch_raw_try_job_results = lambda **_: [
         {
             'builder_name': 'some-builder',
             'status': 'STARTED',
             'result': None,
             'url': None,
         },
     ]
     self.assertEqual(
         git_cl.wait_for_try_jobs(),
         CLStatus(
             status='closed',
             try_job_results={
                 Build('some-builder', None): TryJobStatus('STARTED', None),
             },
         ))
     self.assertEqual(host.stdout.getvalue(),
                      'Waiting for try jobs, timeout: 7200 seconds.\n')
Ejemplo n.º 28
0
 def test_some_commands_not_run_with_auth(self):
     host = MockHost()
     host.executive = MockExecutive(output='mock-output')
     git_cl = GitCL(host, auth_refresh_token_json='token.json')
     git_cl.run(['issue'])
     self.assertEqual(host.executive.calls, [['git', 'cl', 'issue']])
Ejemplo n.º 29
0
 def test_get_issue_number_nothing_in_output(self):
     host = MockHost()
     host.executive = MockExecutive(output='Bogus output')
     git_cl = GitCL(host)
     self.assertEqual(git_cl.get_issue_number(), 'None')
Ejemplo n.º 30
0
 def test_get_issue_number_none(self):
     host = MockHost()
     host.executive = MockExecutive(output='Issue number: None (None)')
     git_cl = GitCL(host)
     self.assertEqual(git_cl.get_issue_number(), 'None')