Merge "Increase Account Auditor Test Code Coverage"
This commit is contained in:
commit
cd0e2c23ef
@ -36,6 +36,7 @@ class AccountAuditor(Daemon):
|
||||
self.devices = conf.get('devices', '/srv/node')
|
||||
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
||||
self.interval = int(conf.get('interval', 1800))
|
||||
self.logging_interval = 3600 # once an hour
|
||||
self.account_passes = 0
|
||||
self.account_failures = 0
|
||||
self.accounts_running_time = 0
|
||||
@ -53,7 +54,7 @@ class AccountAuditor(Daemon):
|
||||
logger=self.logger)
|
||||
for path, device, partition in all_locs:
|
||||
self.account_audit(path)
|
||||
if time.time() - reported >= 3600: # once an hour
|
||||
if time.time() - reported >= self.logging_interval:
|
||||
self.logger.info(_('Since %(time)s: Account audits: '
|
||||
'%(passed)s passed audit,'
|
||||
'%(failed)s failed audit'),
|
||||
|
@ -20,6 +20,7 @@ import os
|
||||
import random
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree
|
||||
from eventlet import Timeout
|
||||
|
||||
from swift.account import auditor
|
||||
from test.unit import FakeLogger
|
||||
@ -91,6 +92,17 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEqual(test_auditor.account_failures, 2 * call_times)
|
||||
self.assertEqual(test_auditor.account_passes, 3 * call_times)
|
||||
|
||||
# now force timeout path code coverage
|
||||
def fake_one_audit_pass(reported):
|
||||
raise Timeout()
|
||||
|
||||
with mock.patch('swift.account.auditor.AccountAuditor._one_audit_pass',
|
||||
fake_one_audit_pass):
|
||||
with mock.patch('swift.account.auditor.time', FakeTime()):
|
||||
self.assertRaises(ValueError, test_auditor.run_forever)
|
||||
self.assertEqual(test_auditor.account_failures, 2 * call_times)
|
||||
self.assertEqual(test_auditor.account_passes, 3 * call_times)
|
||||
|
||||
@mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker)
|
||||
def test_run_once(self):
|
||||
conf = {}
|
||||
@ -106,6 +118,23 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEqual(test_auditor.account_failures, 2)
|
||||
self.assertEqual(test_auditor.account_passes, 3)
|
||||
|
||||
@mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker)
|
||||
def test_one_audit_pass(self):
|
||||
conf = {}
|
||||
test_auditor = auditor.AccountAuditor(conf)
|
||||
|
||||
def fake_audit_location_generator(*args, **kwargs):
|
||||
files = os.listdir(self.testdir)
|
||||
return [(os.path.join(self.testdir, f), '', '') for f in files]
|
||||
|
||||
# force code coverage for logging path
|
||||
test_auditor.logging_interval = 0
|
||||
with mock.patch('swift.account.auditor.audit_location_generator',
|
||||
fake_audit_location_generator):
|
||||
test_auditor._one_audit_pass(test_auditor.logging_interval)
|
||||
self.assertEqual(test_auditor.account_failures, 0)
|
||||
self.assertEqual(test_auditor.account_passes, 0)
|
||||
|
||||
@mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker)
|
||||
def test_account_auditor(self):
|
||||
conf = {}
|
||||
|
Loading…
Reference in New Issue
Block a user