Re-enable test_failed_change_at_head
And "improve" it to use the new build/history assertions. Add an "ordered" option to assertHistory so that we can assert everything about the history except that the builds arrived in the specified order. In this case, aborted builds don't always finish in order. Also add the ordered option to test_failed_changes since it is subject to the same issue. Change-Id: I7b3bec798b462568d4c44db8943daaeb27728735
This commit is contained in:
parent
70911a7302
commit
b536ecc6ea
|
@ -1483,7 +1483,7 @@ class ZuulTestCase(BaseTestCase):
|
|||
self.log.error("No running builds")
|
||||
raise
|
||||
|
||||
def assertHistory(self, history):
|
||||
def assertHistory(self, history, ordered=True):
|
||||
"""Assert that the completed builds are as described.
|
||||
|
||||
The list of completed builds is examined and must match
|
||||
|
@ -1494,14 +1494,37 @@ class ZuulTestCase(BaseTestCase):
|
|||
history, and each element of the dictionary must match the
|
||||
corresponding attribute of the build.
|
||||
|
||||
:arg bool ordered: If true, the history must match the order
|
||||
supplied, if false, the builds are permitted to have
|
||||
arrived in any order.
|
||||
|
||||
"""
|
||||
def matches(history_item, item):
|
||||
for k, v in item.items():
|
||||
if getattr(history_item, k) != v:
|
||||
return False
|
||||
return True
|
||||
try:
|
||||
self.assertEqual(len(self.history), len(history))
|
||||
for i, d in enumerate(history):
|
||||
for k, v in d.items():
|
||||
self.assertEqual(
|
||||
getattr(self.history[i], k), v,
|
||||
"Element %i in history does not match" % (i,))
|
||||
if ordered:
|
||||
for i, d in enumerate(history):
|
||||
if not matches(self.history[i], d):
|
||||
raise Exception(
|
||||
"Element %i in history does not match" % (i,))
|
||||
else:
|
||||
unseen = self.history[:]
|
||||
for i, d in enumerate(history):
|
||||
found = False
|
||||
for unseen_item in unseen:
|
||||
if matches(unseen_item, d):
|
||||
found = True
|
||||
unseen.remove(unseen_item)
|
||||
break
|
||||
if not found:
|
||||
raise Exception("No match found for element %i "
|
||||
"in history" % (i,))
|
||||
if unseen:
|
||||
raise Exception("Unexpected items in history")
|
||||
except Exception:
|
||||
for build in self.history:
|
||||
self.log.error("Completed build: %s" % build)
|
||||
|
|
|
@ -262,7 +262,7 @@ class TestScheduler(ZuulTestCase):
|
|||
dict(name='project-merge', result='SUCCESS', changes='2,1'),
|
||||
dict(name='project-test1', result='SUCCESS', changes='2,1'),
|
||||
dict(name='project-test2', result='SUCCESS', changes='2,1'),
|
||||
])
|
||||
], ordered=False)
|
||||
|
||||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(B.data['status'], 'MERGED')
|
||||
|
@ -331,7 +331,6 @@ class TestScheduler(ZuulTestCase):
|
|||
self.assertEqual(B.reported, 2)
|
||||
self.assertEqual(C.reported, 2)
|
||||
|
||||
@skip("Disabled for early v3 development")
|
||||
def test_failed_change_at_head(self):
|
||||
"Test that if a change at the head fails, jobs behind it are canceled"
|
||||
|
||||
|
@ -351,9 +350,9 @@ class TestScheduler(ZuulTestCase):
|
|||
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(len(self.builds), 1)
|
||||
self.assertEqual(self.builds[0].name, 'project-merge')
|
||||
self.assertTrue(self.job_has_changes(self.builds[0], A))
|
||||
self.assertBuilds([
|
||||
dict(name='project-merge', changes='1,1'),
|
||||
])
|
||||
|
||||
self.launch_server.release('.*-merge')
|
||||
self.waitUntilSettled()
|
||||
|
@ -362,27 +361,84 @@ class TestScheduler(ZuulTestCase):
|
|||
self.launch_server.release('.*-merge')
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(len(self.builds), 6)
|
||||
self.assertEqual(self.builds[0].name, 'project-test1')
|
||||
self.assertEqual(self.builds[1].name, 'project-test2')
|
||||
self.assertEqual(self.builds[2].name, 'project-test1')
|
||||
self.assertEqual(self.builds[3].name, 'project-test2')
|
||||
self.assertEqual(self.builds[4].name, 'project-test1')
|
||||
self.assertEqual(self.builds[5].name, 'project-test2')
|
||||
self.assertBuilds([
|
||||
dict(name='project-test1', changes='1,1'),
|
||||
dict(name='project-test2', changes='1,1'),
|
||||
dict(name='project-test1', changes='1,1 2,1'),
|
||||
dict(name='project-test2', changes='1,1 2,1'),
|
||||
dict(name='project-test1', changes='1,1 2,1 3,1'),
|
||||
dict(name='project-test2', changes='1,1 2,1 3,1'),
|
||||
])
|
||||
|
||||
self.release(self.builds[0])
|
||||
self.waitUntilSettled()
|
||||
|
||||
# project-test2, project-merge for B
|
||||
self.assertEqual(len(self.builds), 2)
|
||||
self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4)
|
||||
self.assertBuilds([
|
||||
dict(name='project-test2', changes='1,1'),
|
||||
dict(name='project-merge', changes='2,1'),
|
||||
])
|
||||
# Unordered history comparison because the aborts can finish
|
||||
# in any order.
|
||||
self.assertHistory([
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1 2,1 3,1'),
|
||||
dict(name='project-test1', result='FAILURE',
|
||||
changes='1,1'),
|
||||
dict(name='project-test1', result='ABORTED',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-test2', result='ABORTED',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-test1', result='ABORTED',
|
||||
changes='1,1 2,1 3,1'),
|
||||
dict(name='project-test2', result='ABORTED',
|
||||
changes='1,1 2,1 3,1'),
|
||||
], ordered=False)
|
||||
|
||||
self.launch_server.hold_jobs_in_build = False
|
||||
self.launch_server.release()
|
||||
self.launch_server.release('.*-merge')
|
||||
self.waitUntilSettled()
|
||||
self.launch_server.release('.*-merge')
|
||||
self.waitUntilSettled()
|
||||
self.orderedRelease()
|
||||
|
||||
self.assertBuilds([])
|
||||
self.assertHistory([
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='1,1 2,1 3,1'),
|
||||
dict(name='project-test1', result='FAILURE',
|
||||
changes='1,1'),
|
||||
dict(name='project-test1', result='ABORTED',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-test2', result='ABORTED',
|
||||
changes='1,1 2,1'),
|
||||
dict(name='project-test1', result='ABORTED',
|
||||
changes='1,1 2,1 3,1'),
|
||||
dict(name='project-test2', result='ABORTED',
|
||||
changes='1,1 2,1 3,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='2,1'),
|
||||
dict(name='project-merge', result='SUCCESS',
|
||||
changes='2,1 3,1'),
|
||||
dict(name='project-test2', result='SUCCESS',
|
||||
changes='1,1'),
|
||||
dict(name='project-test1', result='SUCCESS',
|
||||
changes='2,1'),
|
||||
dict(name='project-test2', result='SUCCESS',
|
||||
changes='2,1'),
|
||||
dict(name='project-test1', result='SUCCESS',
|
||||
changes='2,1 3,1'),
|
||||
dict(name='project-test2', result='SUCCESS',
|
||||
changes='2,1 3,1'),
|
||||
], ordered=False)
|
||||
|
||||
self.assertEqual(len(self.builds), 0)
|
||||
self.assertEqual(len(self.history), 15)
|
||||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(B.data['status'], 'MERGED')
|
||||
self.assertEqual(C.data['status'], 'MERGED')
|
||||
|
|
Loading…
Reference in New Issue