Speed up test_inventory

The config/inventory fixture defines seven jobs, each needs merges and a
configuration to be prepared but the tests only assert against a single
job.

To reduce the overhead, hold the jobs at Gearman level to prevent them
from triggering merge operations and config loading.

Release solely the job for which we want to test the inventory.

When tearing down the job, cancel all remaining builds directly in
Gearman. That has shown to be faster than crafting an abandoned change.
The canceled jobs will bubble up to the pipeline manager and please our
suite assertFinalState() which requires that no items are left in any
pipeline managers queue.

By saving all the overhead of merge / ansible run etc, the tests locally
run more than twice faster than before.

Change-Id: Id7ffe741dcf82b1cb60099abc331ddc95cac8b3c
This commit is contained in:
Antoine Musso 2020-01-28 14:30:24 +01:00
parent 000f6ec21e
commit 50487d62f6
1 changed files with 21 additions and 0 deletions

View File

@ -32,6 +32,8 @@ class TestInventoryBase(ZuulTestCase):
if python_path:
self.fake_nodepool.python_path = python_path
self.executor_server.hold_jobs_in_build = True
self.gearman_server.hold_jobs_in_queue = True
if self.use_gerrit:
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
@ -42,17 +44,36 @@ class TestInventoryBase(ZuulTestCase):
self.waitUntilSettled()
def tearDown(self):
self.cancelExecutorJobs()
self.waitUntilSettled()
super(TestInventoryBase, self).tearDown()
def _get_build_inventory(self, name):
self.runJob(name)
build = self.getBuildByName(name)
inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml')
return yaml.safe_load(open(inv_path, 'r'))
def _get_setup_inventory(self, name):
self.runJob(name)
build = self.getBuildByName(name)
setup_inv_path = os.path.join(build.jobdir.root, 'ansible',
'setup-inventory.yaml')
return yaml.safe_load(open(setup_inv_path, 'r'))
def runJob(self, name):
self.gearman_server.hold_jobs_in_queue = False
self.gearman_server.release('^%s$' % name)
self.waitUntilSettled()
def cancelExecutorJobs(self):
builds = [b for b in self.executor_client.builds.values()]
for build in builds:
self.executor_client.cancelJobInQueue(build)
class TestInventoryGithub(TestInventoryBase):