Make fake test Gerrit merger more realistic
The current Gerrit simulated merge operation simply resets the target branch to the specified change's commit -- it doesn't actually perform a git merge operation as gerrit (typically) would. This makes some test situations difficult, such as when we want to rely on a post-merge pipeline preparing git repos on top of previously merged changes. This change actually performs git merge operations when gerrit changes are merged in tests, so the result should be far more realistic. One test relied on a side effect of the old behavior: test_zuul_trigger_project_change_merged This test merges change A and then performed a merge check on change B, which conflicts, and then reports Verified -1. It then repeats the test by merging change D which conflicts with change E which should also receive Verified -1. However, the test inadvertently ran a second merge check on change B when change D merged, but because it tested D as written instead of merged on top of A after A was merged, the conflict of B against A was not seen (because B does not conflict with D) and therefore not rported. With this patch, the conflict of B against the merged change A is seen and the test failed because it reported B's merge conflict twice. To correct this, we make the test even more realistic by adding a pipeline requirement that we have not already reported Verified -1 in order to enqueue a change for merge-check. In order for this to work, we need to make sure Zuul sees the comment-added events for the Verified -1 votes (so that the Gerrit driver updates its view of the votes on the change), so those are added to the test. Change-Id: Ia5b4b83096de3b8719c8b6d256e8e33749e7a5b8
This commit is contained in:
parent
22640baef4
commit
15ef181d26
|
@ -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
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
name: merge-check
|
||||
manager: independent
|
||||
ignore-dependencies: true
|
||||
reject:
|
||||
gerrit:
|
||||
approval:
|
||||
- Verified: -1
|
||||
trigger:
|
||||
zuul:
|
||||
- event: project-change-merged
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue