Merge "Sleep between object ZBF process forks"
This commit is contained in:
commit
59a639c116
@ -279,6 +279,8 @@ class ObjectAuditor(Daemon):
|
||||
if self.conf_zero_byte_fps and pid == zbf_pid and \
|
||||
len(pids) > 1:
|
||||
kwargs['device_dirs'] = override_devices
|
||||
# sleep between ZBF scanner forks
|
||||
self._sleep()
|
||||
zbf_pid = self.fork_child(zero_byte_fps=True, **kwargs)
|
||||
pids.append(zbf_pid)
|
||||
pids.remove(pid)
|
||||
|
@ -440,9 +440,12 @@ class TestAuditor(unittest.TestCase):
|
||||
if 'zero_byte_fps' in kwargs:
|
||||
self.check_device_dir = kwargs.get('device_dirs')
|
||||
|
||||
def mock_sleep(self):
|
||||
def mock_sleep_stop(self):
|
||||
raise StopForever('stop')
|
||||
|
||||
def mock_sleep_continue(self):
|
||||
return
|
||||
|
||||
def mock_audit_loop_error(self, parent, zbo_fps,
|
||||
override_devices=None, **kwargs):
|
||||
raise Bogus('exception')
|
||||
@ -469,12 +472,12 @@ class TestAuditor(unittest.TestCase):
|
||||
real_audit_loop = my_auditor.audit_loop
|
||||
my_auditor.audit_loop = mocker.mock_audit_loop_error
|
||||
my_auditor.run_audit = mocker.mock_run
|
||||
my_auditor._sleep = mocker.mock_sleep
|
||||
was_fork = os.fork
|
||||
was_wait = os.wait
|
||||
os.fork = mocker.mock_fork
|
||||
os.wait = mocker.mock_wait
|
||||
try:
|
||||
my_auditor._sleep = mocker.mock_sleep_stop
|
||||
my_auditor.run_once(zero_byte_fps=50)
|
||||
my_auditor.logger.exception.assert_called_once_with(
|
||||
'ERROR auditing: exception')
|
||||
@ -489,10 +492,10 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEquals(mocker.check_kwargs['zero_byte_fps'], 50)
|
||||
self.assertEquals(mocker.fork_called, 0)
|
||||
|
||||
self.assertRaises(SystemExit, my_auditor.run_forever)
|
||||
self.assertRaises(SystemExit, my_auditor.run_once)
|
||||
self.assertEquals(mocker.fork_called, 1)
|
||||
self.assertEquals(mocker.check_kwargs['zero_byte_fps'], 89)
|
||||
self.assertEquals(mocker.check_device_dir, None)
|
||||
self.assertEquals(mocker.check_device_dir, [])
|
||||
self.assertEquals(mocker.check_args, ())
|
||||
|
||||
device_list = ['sd%s' % i for i in string.ascii_letters[2:10]]
|
||||
@ -510,6 +513,17 @@ class TestAuditor(unittest.TestCase):
|
||||
|
||||
mocker.fork_called = 0
|
||||
self.assertRaises(StopForever, my_auditor.run_forever)
|
||||
# Fork is called 2 times since the zbf process is forked just
|
||||
# once before self._sleep() is called and StopForever is raised
|
||||
# Also wait is called just once before StopForever is raised
|
||||
self.assertEquals(mocker.fork_called, 2)
|
||||
self.assertEquals(mocker.wait_called, 1)
|
||||
|
||||
my_auditor._sleep = mocker.mock_sleep_continue
|
||||
|
||||
mocker.fork_called = 0
|
||||
mocker.wait_called = 0
|
||||
my_auditor.run_once()
|
||||
# Fork is called 3 times since the zbf process is forked twice
|
||||
self.assertEquals(mocker.fork_called, 3)
|
||||
self.assertEquals(mocker.wait_called, 3)
|
||||
|
Loading…
Reference in New Issue
Block a user