Mock system load in executor governor tests

We've seen occasional test failures of test_slow_start [1]. This fails
because the executor unregisters due to high system load on the test
node. However we want to test isolated reasons so mock the system load
in those test cases. The test_hdd_governor and test_pause_governor
have the same issue.

[1] Trace:
zuul.ExecutorServer              INFO     Unregistering due to high system load 20.21 > 20.0
Traceback (most recent call last):
  File "/home/zuul/src/git.openstack.org/openstack-infra/zuul/tests/unit/test_executor.py", line 616, in test_slow_start
    self.assertTrue(self.executor_server.accepting_work)
  File "/home/zuul/src/git.openstack.org/openstack-infra/zuul/.tox/py35/lib/python3.5/site-packages/unittest2/case.py", line 702, in assertTrue
    raise self.failureException(msg)
AssertionError: False is not true

Change-Id: Ib6cd3c894c51e03ea76b6d18282e8bd88b335538
This commit is contained in:
Tobias Henkel 2019-03-23 15:00:04 +01:00
parent d75467e625
commit 2c4f9ec6da
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 10 additions and 3 deletions

View File

@ -531,8 +531,9 @@ class TestGovernor(ZuulTestCase):
self.executor_server.manageLoad()
self.assertFalse(self.executor_server.accepting_work)
@mock.patch('os.getloadavg')
@mock.patch('os.statvfs')
def test_hdd_governor(self, statvfs_mock):
def test_hdd_governor(self, statvfs_mock, loadavg_mock):
class Dummy(object):
pass
hdd = Dummy()
@ -540,6 +541,7 @@ class TestGovernor(ZuulTestCase):
hdd.f_blocks = 120920708
hdd.f_bfree = 95716701
statvfs_mock.return_value = hdd # 20.84% used
loadavg_mock.return_value = (0.0, 0.0, 0.0)
self.executor_server.manageLoad()
self.assertTrue(self.executor_server.accepting_work)
@ -558,7 +560,10 @@ class TestGovernor(ZuulTestCase):
'zuul.executor.test-executor-hostname_example_com.pct_used_hdd',
value='9527', kind='g')
def test_pause_governor(self):
@mock.patch('os.getloadavg')
def test_pause_governor(self, loadavg_mock):
loadavg_mock.return_value = (0.0, 0.0, 0.0)
self.executor_server.manageLoad()
self.assertTrue(self.executor_server.accepting_work)
@ -589,7 +594,9 @@ class TestGovernor(ZuulTestCase):
self.log.debug("Worker for %s started: %s", jobname, worker.started)
return build
def test_slow_start(self):
@mock.patch('os.getloadavg')
def test_slow_start(self, loadavg_mock):
loadavg_mock.return_value = (0.0, 0.0, 0.0)
def _set_starting_builds(min, max):
for sensor in self.executor_server.sensors: