def testSucessfulPushTryJob(self, mock_post, *_):
        mock_build = Build()
        mock_build.id = 8945610992972640896
        mock_build.status = 12
        mock_build.output.properties['mastername'] = 'luci.chromium.findit'
        mock_build.output.properties['buildername'] = ('findit_variable')
        mock_build.output.properties['target_mastername'] = 'chromium.linux'
        mock_build.output.properties['target_buildername'] = (
            'linux_chromium_compile_dbg_ng')
        mock_build.output.properties.get_or_create_struct(
            'swarm_hashes_ref/heads/mockmaster(at){#123}_with_patch'
        )['mock_target'] = 'mock_hash'
        mock_build.output.properties.get_or_create_struct(
            'swarm_hashes_ref/heads/mockmaster(at){#123}_without_patch'
        )['mock_target'] = 'mock_hash_without'
        mock_build.output.properties['repository'] = (
            'https://test.googlesource.com/team/project.git')
        mock_build.output.properties['gitiles_ref'] = 'refs/heads/mockmaster'
        mock_change = mock_build.input.gerrit_changes.add()
        mock_change.host = 'mock.gerrit.host'
        mock_change.change = 12345
        mock_change.patchset = 1
        mock_build.builder.project = 'mock_luci_project'
        mock_build.builder.bucket = 'mock_bucket'
        mock_build.builder.builder = 'findit_variable'
        mock_headers = {'X-Prpc-Grpc-Code': '0'}
        binary_data = mock_build.SerializeToString()
        mock_post.return_value = (200, binary_data, mock_headers)

        request_body = json.dumps({
            'message': {
                'attributes': {
                    'build_id': str(mock_build.id),
                },
                'data':
                base64.b64encode(
                    json.dumps({
                        'build': {
                            'project': 'chromium',
                            'bucket': 'luci.chromium.ci',
                            'status': 'COMPLETED',
                            'parameters_json': '{"builder_name": "builder"}',
                        }
                    })),
            },
        })
        response = self.test_app.post('/index-isolated-builds?format=json',
                                      params=request_body)
        self.assertEqual(200, response.status_int)
        self.assertEqual(
            123,
            IsolatedTarget.get_by_id(
                '8945610992972640896/mock_target').commit_position)
        self.assertEqual(2, len(json.loads(response.body)['created_rows']))

        # Ensure target values were used.
        entry = IsolatedTarget.get_by_id('8945610992972640896/mock_target')
        self.assertEqual('chromium.linux', entry.master_name)
        self.assertEqual('linux_chromium_compile_dbg_ng', entry.builder_name)
    def testSucessfulPushCIBuild(self, mock_post, *_):
        mock_build = Build()
        mock_build.id = 8945610992972640896
        mock_build.status = 12
        mock_build.output.properties['mastername'] = 'chromium.linux'
        mock_build.output.properties['buildername'] = 'Linux Builder'
        mock_build.output.properties.get_or_create_struct(
            'swarm_hashes_ref/heads/mockmaster(at){#123}'
        )['mock_target'] = 'mock_hash'
        gitiles_commit = mock_build.input.gitiles_commit
        gitiles_commit.host = 'gitiles.host'
        gitiles_commit.project = 'gitiles/project'
        gitiles_commit.ref = 'refs/heads/mockmaster'
        mock_build.builder.project = 'mock_luci_project'
        mock_build.builder.bucket = 'mock_bucket'
        mock_build.builder.builder = 'Linux Builder'
        mock_headers = {'X-Prpc-Grpc-Code': '0'}
        binary_data = mock_build.SerializeToString()
        mock_post.return_value = (200, binary_data, mock_headers)

        request_body = json.dumps({
            'message': {
                'attributes': {
                    'build_id': str(mock_build.id),
                },
                'data':
                base64.b64encode(
                    json.dumps({
                        'build': {
                            'project': 'chromium',
                            'bucket': 'luci.chromium.ci',
                            'status': 'COMPLETED',
                            'parameters_json': '{"builder_name": "builder"}',
                        }
                    })),
            },
        })
        response = self.test_app.post('/index-isolated-builds?format=json',
                                      params=request_body)
        self.assertEqual(200, response.status_int)
        self.assertEqual(
            123,
            IsolatedTarget.get_by_id(
                '8945610992972640896/mock_target').commit_position)
        self.assertEqual(
            8945610992972640896,
            IsolatedTarget.get_by_id(
                '8945610992972640896/mock_target').build_id)
        self.assertEqual(1, len(json.loads(response.body)['created_rows']))
Example #3
0
 def testFindIsolate(self):
   before = IsolatedTarget.FindIsolateBeforeCommitPositionByBucket(
       'chromium', 'ci', 'Linux Builder', 'chromium.googlesource.com',
       'chromium/src', 'refs/heads/master', 'browser_tests', 55650)
   self.assertEqual(before[0],
                    IsolatedTarget.get_by_id('843400990909049/browser_tests'))
   at = IsolatedTarget.FindIsolateAtOrAfterCommitPositionByBucket(
       'chromium', 'ci', 'Linux Builder', 'chromium.googlesource.com',
       'chromium/src', 'refs/heads/master', 'browser_tests', 55650)
   self.assertEqual(at[0],
                    IsolatedTarget.get_by_id('843400990909050/browser_tests'))
   after = IsolatedTarget.FindIsolateAtOrAfterCommitPositionByBucket(
       'chromium', 'ci', 'Linux Builder', 'chromium.googlesource.com',
       'chromium/src', 'refs/heads/master', 'browser_tests', 55655)
   self.assertEqual(after[0],
                    IsolatedTarget.get_by_id('843400990909051/browser_tests'))