def testSuccess(self, commit_range): commit_range.return_value = [ { 'commit': 'babe852' }, { 'commit': 'b57345e' }, { 'commit': '949b36d' }, { 'commit': '1ef4789' }, ] commit_a = commit.Commit('chromium', '0e57e2b') commit_b = commit.Commit('chromium', 'babe852') self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit.Commit('chromium', '949b36d'))
def testContinuousMidpointWithMergeCommits(self): def _Midpoints(start_point, end_point): midpoint = commit.Commit.Midpoint(start_point, end_point) while midpoint.git_hash != start_point.git_hash: yield midpoint start_point = midpoint midpoint = commit.Commit.Midpoint(start_point, end_point) start = commit.Commit(repository='chromium', git_hash='mc_1') end = commit.Commit(repository='chromium', git_hash='mc_100') count = 0 matcher = re.compile(r'^mc_\d+$') for midpoint in _Midpoints(start, end): self.assertRegexpMatches(midpoint.git_hash, matcher) count += 1 self.assertLess(count, 100) # Check that the midpoint search algorithm runs in log2(N) time. self.assertGreater(count, 0) self.assertLess(count, 8)
def testChange(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba') p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') # Also test the deps conversion to frozenset. c = change.Change([base_commit, dep], p) self.assertEqual(c, change.Change((base_commit, dep), p)) string = 'chromium@aaa7336 catapult@e0a2efb + 2f0d5c7' id_string = ('catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba ' 'chromium@aaa7336c821888839f759c6c0a36b56c + ' 'https://codereview.com/672011/2f0d5c7') self.assertEqual(str(c), string) self.assertEqual(c.id_string, id_string) self.assertEqual(c.base_commit, base_commit) self.assertEqual(c.last_commit, dep) self.assertEqual(c.deps, (dep,)) self.assertEqual(c.commits, (base_commit, dep)) self.assertEqual(c.patch, p)
def _CreateJob(self, hash1, hash2, comparison_mode, created, bug_id, exception=None): old_commit = commit.Commit('chromium', hash1) change_a = change_module.Change((old_commit, )) old_commit = commit.Commit('chromium', hash2) change_b = change_module.Change((old_commit, )) job = job_module.Job.New((_QuestStub(), ), (change_a, change_b), comparison_mode=comparison_mode, bug_id=bug_id) job.created = created job.exception = exception job.state.ScheduleWork() job.state.Explore() job.put()
def testDeps(self, file_contents): file_contents.return_value = """ vars = { 'chromium_git': 'https://chromium.googlesource.com', } deps = { 'src/v8': Var('chromium_git') + '/v8/v8.git' + '@' + 'c092edb', } deps_os = { 'win': { 'src/third_party/cygwin': Var('chromium_git') + '/chromium/deps/cygwin.git' + '@' + 'c89e446', } } """ c = commit.Commit('chromium', 'aaa7336') expected = frozenset(( commit.Commit('cygwin', 'c89e446'), commit.Commit('v8', 'c092edb'), )) self.assertEqual(c.Deps(), expected)
def testChange(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba') # Also test the deps conversion to tuple. c = change.Change([base_commit, dep], patch_test.Patch()) self.assertEqual(c, change.Change((base_commit, dep), patch_test.Patch())) string = 'chromium@aaa7336 catapult@e0a2efb + abc123' id_string = ('catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba ' 'chromium@aaa7336c821888839f759c6c0a36b56c + ' 'https://codereview.com/repo~branch~id/abc123') self.assertEqual(str(c), string) self.assertEqual(c.id_string, id_string) self.assertEqual(c.base_commit, base_commit) self.assertEqual(c.last_commit, dep) self.assertEqual(c.deps, (dep, )) self.assertEqual(c.commits, (base_commit, dep)) self.assertEqual(c.patch, patch_test.Patch())
def testAsDict(self, commit_info): commit_info.return_value = _GITILES_COMMIT_INFO c = commit.Commit('chromium', 'aaa7336') expected = { 'repository': 'chromium', 'git_hash': 'aaa7336', 'url': test.CHROMIUM_URL + '/+/aaa7336', 'subject': 'Subject.', 'author': '*****@*****.**', 'time': 'Fri Jan 01 00:01:00 2016', 'commit_position': 437745, } self.assertEqual(c.AsDict(), expected)
def testFromDictWithAllFields(self, get_change): get_change.return_value = { 'id': 'repo~branch~id', 'revisions': {'2f0d5c7': {}} } c = change.Change.FromDict({ 'commits': ( {'repository': 'chromium', 'git_hash': 'aaa7336'}, {'repository': 'catapult', 'git_hash': 'e0a2efb'}, ), 'patch': { 'server': 'https://codereview.com', 'change': 672011, 'revision': '2f0d5c7', }, }) commits = (commit.Commit('chromium', 'aaa7336'), commit.Commit('catapult', 'e0a2efb')) p = patch.GerritPatch('https://codereview.com', 'repo~branch~id', '2f0d5c7') expected = change.Change(commits, p) self.assertEqual(c, expected)
def testChange(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba') p = patch.Patch('https://codereview.chromium.org', 2565263002, 20001) # Also test the deps conversion to frozenset. c = change.Change([base_commit, dep], p) self.assertEqual(c, change.Change((base_commit, dep), p)) string = ('chromium@aaa7336 catapult@e0a2efb + ' 'https://codereview.chromium.org/2565263002/20001') id_string = ('chromium@aaa7336c821888839f759c6c0a36b56c ' 'catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba + ' 'https://codereview.chromium.org/2565263002/20001') self.assertEqual(str(c), string) self.assertEqual(c.id_string, id_string) self.assertEqual(c.base_commit, base_commit) self.assertEqual(c.last_commit, dep) self.assertEqual(c.deps, (dep, )) self.assertEqual(c.commits, (base_commit, dep)) self.assertEqual(c.patch, p)
def testFromDictWithAllFields(self, _): c = change.Change.FromDict({ 'commits': ( { 'repository': 'chromium', 'git_hash': 'aaa7336' }, { 'repository': 'catapult', 'git_hash': 'e0a2efb' }, ), 'patch': { 'server': 'https://codereview.chromium.org', 'issue': 2565263002, 'patchset': 20001, }, }) commits = (commit.Commit('chromium', 'aaa7336'), commit.Commit('catapult', 'e0a2efb')) p = patch.Patch('https://codereview.chromium.org', 2565263002, 20001) expected = change.Change(commits, p) self.assertEqual(c, expected)
def testFromDict_Caches(self, mock_put): c = commit.Commit.FromDict({ 'repository': test.CHROMIUM_URL, 'git_hash': 'HEAD', }) expected = commit.Commit('chromium', 'git hash at HEAD') self.assertEqual(c, expected) mock_put.assert_called_once_with(expected.id_string, mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY, memcache_timeout=1800)
def __call__(self, task, _, change): if task.status == 'ongoing': logging.warning( 'Ignoring an initiate event on an ongoing task; task = %s', task.id) return None # Outline: # - Check if we can find the isolate for this revision. # - If found, update the payload of the task and update accumulator with # result for this task. # - If not found, schedule a build for this revision, update the task # payload with the build details, wait for updates. try: change = change_module.Change(commits=[ commit_module.Commit(c['repository'], c['git_hash']) for c in task.payload.get('change', {}).get('commits', []) ], patch=task.payload.get('patch')) logging.debug('Looking up isolate for change = %s', change) isolate_server, isolate_hash = isolate.Get( task.payload.get('builder'), change, task.payload.get('target')) task.payload.update({ 'isolate_server': isolate_server, 'isolate_hash': isolate_hash, }) # At this point we've found an isolate from a previous build, so we mark # the task 'completed' and allow tasks that depend on the isolate to see # this information. @task_module.LogStateTransitionFailures def CompleteWithCachedIsolate(_): task_module.UpdateTask(self.job, task.id, new_state='completed', payload=task.payload) return [CompleteWithCachedIsolate] except KeyError as e: logging.error('Failed to find isolate for task = %s;\nError: %s', task.id, e) return [ScheduleBuildAction(self.job, task, change)] return None
def testDeps(self, file_contents): file_contents.return_value = """ vars = { 'chromium_git': 'https://chromium.googlesource.com', 'webrtc_git': 'https://webrtc.googlesource.com', 'webrtc_rev': 'deadbeef', } deps = { 'src/v8': Var('chromium_git') + '/v8/v8.git' + '@' + 'c092edb', 'src/third_party/lighttpd': { 'url': Var('chromium_git') + '/deps/lighttpd.git' + '@' + '9dfa55d', 'condition': 'checkout_mac or checkout_win', }, 'src/third_party/webrtc': { 'url': '{webrtc_git}/src.git', 'revision': '{webrtc_rev}', }, 'src/third_party/intellij': { 'packages': [{ 'package': 'chromium/third_party/intellij', 'version': 'version:12.0-cr0', }], 'condition': 'checkout_android', 'dep_type': 'cipd', }, } deps_os = { 'win': { 'src/third_party/cygwin': Var('chromium_git') + '/chromium/deps/cygwin.git' + '@' + 'c89e446', } } """ c = commit.Commit('chromium', 'aaa7336') expected = frozenset(( ('https://chromium.googlesource.com/chromium/deps/cygwin', 'c89e446'), ('https://chromium.googlesource.com/deps/lighttpd', '9dfa55d'), ('https://chromium.googlesource.com/v8/v8', 'c092edb'), ('https://webrtc.googlesource.com/src', 'deadbeef'), )) self.assertEqual(c.Deps(), expected)
def Commit(number, repository='chromium'): return commit.Commit(repository=repository, git_hash='commit_' + str(number))
def testDifferingCommitCount(self): change_a = change.Change((commit.Commit('chromium', 0),)) change_b = change.Change((commit.Commit('chromium', 9), commit.Commit('another_repo', 'babe852'))) with self.assertRaises(commit.NonLinearError): change.Change.Midpoint(change_a, change_b)
def testRaisesWithDifferingRepositories(self): commit_a = commit.Commit('chromium', '0e57e2b') commit_b = commit.Commit('not_chromium', 'babe852') with self.assertRaises(commit.NonLinearError): commit.Commit.Midpoint(commit_a, commit_b)
def testAdjacentCommits(self, commit_range): commit_range.return_value = [{'commit': 'b57345e'}] commit_a = commit.Commit('chromium', '949b36d') commit_b = commit.Commit('chromium', 'b57345e') self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a)
def testSameCommit(self): commit_a = commit.Commit('chromium', '0e57e2b') commit_b = commit.Commit('chromium', '0e57e2b') self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a)
def testUpdateWithMultiplePatches(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') c = change.Change((base_commit,), p) with self.assertRaises(NotImplementedError): c.Update(c)
def testNotAdjacent(self): change_a = change.Change((commit.Commit('chromium', 0), )) change_b = change.Change((commit.Commit('chromium', 9), )) self.assertEqual(change.Change.Midpoint(change_a, change_b), change.Change((commit.Commit('chromium', 4), )))
def testAdjacentWithDepsRoll(self): change_a = change.Change((commit.Commit('chromium', 4), )) change_b = change.Change((commit.Commit('chromium', 5), )) expected = change.Change( (commit.Commit('chromium', 4), commit.Commit('catapult', 4))) self.assertEqual(change.Change.Midpoint(change_a, change_b), expected)
def testAdjacentWithNoDepsRoll(self): change_a = change.Change((commit.Commit('chromium', 0), )) change_b = change.Change((commit.Commit('chromium', 1), )) with self.assertRaises(commit.NonLinearError): change.Change.Midpoint(change_a, change_b)
def testSameChange(self): change_a = change.Change((commit.Commit('chromium', 0), )) change_b = change.Change((commit.Commit('chromium', 0), )) with self.assertRaises(commit.NonLinearError): change.Change.Midpoint(change_a, change_b)
def Commit(number, repository='chromium'): return commit.Commit(repository, 'commit ' + str(number))
def testFromDepNewRepo(self): dep = commit.Dep('https://new/repository/url.git', 'git_hash') c = commit.Commit.FromDep(dep) self.assertEqual(c, commit.Commit('url', 'git_hash'))
def testFromDepExistingRepo(self): c = commit.Commit.FromDep(commit.Dep(test.CHROMIUM_URL, 'git_hash')) self.assertEqual(c, commit.Commit('chromium', 'git_hash'))
def testDifferingRepository(self): change_a = change.Change((commit.Commit('chromium', '0e57e2b'), )) change_b = change.Change((commit.Commit('another_repo', 'babe852'), )) with self.assertRaises(commit.NonLinearError): change.Change.Midpoint(change_a, change_b)
def testMidpointWithMergeCommits(self): midpoint = commit.Commit.Midpoint( commit.Commit(repository='chromium', git_hash='commit_0'), commit.Commit(repository='chromium', git_hash='mc_4')) self.assertEqual(midpoint, commit.Commit(repository='chromium', git_hash='commit_2'))