Merge "Make fake test Gerrit merger more realistic"

This commit is contained in:
Zuul 2020-05-07 16:23:00 +00:00 committed by Gerrit Code Review
commit 42ff349bd2
4 changed files with 16 additions and 10 deletions

View File

@ -638,8 +638,11 @@ class FakeGerritChange(object):
path = os.path.join(self.upstream_root, self.project)
repo = git.Repo(path)
repo.heads[self.branch].commit = \
repo.commit(self.patchsets[-1]['revision'])
repo.head.reference = self.branch
zuul.merger.merger.reset_repo_to_head(repo)
repo.git.merge('-s', 'resolve', self.patchsets[-1]['ref'])
repo.heads[self.branch].commit = repo.head.commit
def setReported(self):
self.reported += 1

View File

@ -36,6 +36,10 @@
name: merge-check
manager: independent
ignore-dependencies: true
reject:
gerrit:
approval:
- Verified: -1
trigger:
zuul:
- event: project-change-merged

View File

@ -26,14 +26,7 @@ class TestSerial(ZuulTestCase):
A.setMerged()
self.fake_gerrit.addEvent(A.getChangeMergedEvent())
self.waitUntilSettled()
# The gerrit upstream repo simulation isn't perfect -- when
# change A is merged above, the master ref is updated to point
# to that change, it doesn't actually "merge" it. The same is
# true for B, so if it didn't have A in its git history, then
# A would not appear in the jobs run for B. We simulate the
# correct situation by setting A as the git parent of B.
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B',
parent='refs/changes/1/1/1')
B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
B.setMerged()
self.fake_gerrit.addEvent(B.getChangeMergedEvent())
self.waitUntilSettled()

View File

@ -220,6 +220,12 @@ class TestZuulTriggerProjectChangeMerged(ZuulTestCase):
self.assertTrue("project:{org/project} status:open" in
self.fake_gerrit.queries)
# Ensure the gerrit driver has updated its cache after the
# previous comments were left:
self.fake_gerrit.addEvent(A.getChangeCommentEvent(2))
self.fake_gerrit.addEvent(B.getChangeCommentEvent(2))
self.waitUntilSettled()
# Reconfigure and run the test again. This is a regression
# check to make sure that we don't end up with a stale trigger
# cache that has references to projects from the old