unit tests
This commit is contained in:
parent
c4948587a3
commit
d159356713
1 changed files with 83 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ class ManagedRepoTest(unittest.TestCase):
|
|||
'end_event': None,
|
||||
'id': 2385,
|
||||
'opts': {'debuginfo': False, 'separate_src': False, 'src': False},
|
||||
'custom_opts': {},
|
||||
'state': 1,
|
||||
'state_ts': 1710705227.166751,
|
||||
'tag_id': 50,
|
||||
|
|
@ -126,4 +127,86 @@ class ManagedRepoTest(unittest.TestCase):
|
|||
self.session.repo.setState.assert_called_once_with(self.repo.id, koji.REPO_DELETED)
|
||||
self.mgr.rmtree.assert_called_once_with(path)
|
||||
|
||||
def test_expire_check_recent(self):
|
||||
self.options.repo_lifetime = 3600 * 24
|
||||
self.options.recheck_period = 3600
|
||||
base_ts = 444888888
|
||||
now = base_ts + 100
|
||||
|
||||
self.repo.data['state'] = koji.REPO_READY
|
||||
self.repo.data['state_ts'] = base_ts
|
||||
self.repo.data['end_event'] = 999
|
||||
|
||||
with mock.patch('time.time') as _time:
|
||||
_time.return_value = now
|
||||
self.repo.expire_check()
|
||||
|
||||
# we should have stopped at the age check
|
||||
self.session.getBuildTargets.assert_not_called()
|
||||
self.session.repoExpire.assert_not_called()
|
||||
|
||||
def test_expire_check_recheck(self):
|
||||
self.options.repo_lifetime = 3600 * 24
|
||||
self.options.recheck_period = 3600
|
||||
base_ts = 444888888
|
||||
now = base_ts + self.options.repo_lifetime + 100
|
||||
|
||||
# recheck period still in effect
|
||||
self.repo.expire_check_ts = now - 3500
|
||||
# otherwise eligible to expire
|
||||
self.repo.data['state'] = koji.REPO_READY
|
||||
self.repo.data['state_ts'] = base_ts
|
||||
self.repo.data['end_event'] = 999
|
||||
|
||||
with mock.patch('time.time') as _time:
|
||||
_time.return_value = now
|
||||
self.repo.expire_check()
|
||||
|
||||
self.session.getBuildTargets.assert_not_called()
|
||||
self.session.repo.query.assert_not_called()
|
||||
self.session.repoExpire.assert_not_called()
|
||||
|
||||
def test_expire_check_latest(self):
|
||||
self.options.repo_lifetime = 3600 * 24
|
||||
self.options.recheck_period = 3600
|
||||
base_ts = 444888888
|
||||
now = base_ts + self.options.repo_lifetime + 100
|
||||
|
||||
self.repo.data['state'] = koji.REPO_READY
|
||||
self.repo.data['state_ts'] = base_ts
|
||||
self.repo.data['end_event'] = 999
|
||||
# latest for a target, should not get expired
|
||||
self.session.getBuildTargets.return_value = ['TARGET']
|
||||
self.session.repo.query.return_value = []
|
||||
|
||||
with mock.patch('time.time') as _time:
|
||||
_time.return_value = now
|
||||
self.repo.expire_check()
|
||||
|
||||
self.session.getBuildTargets.assert_called_once()
|
||||
self.session.repo.query.assert_called_once()
|
||||
self.session.repoExpire.assert_not_called()
|
||||
|
||||
def test_expire_check_expire(self):
|
||||
self.options.repo_lifetime = 3600 * 24
|
||||
self.options.recheck_period = 3600
|
||||
base_ts = 444888888
|
||||
now = base_ts + self.options.repo_lifetime + 100
|
||||
|
||||
self.repo.data['state'] = koji.REPO_READY
|
||||
self.repo.data['state_ts'] = base_ts
|
||||
self.repo.data['end_event'] = 999
|
||||
# not latest
|
||||
self.session.getBuildTargets.return_value = ['TARGET']
|
||||
self.session.repo.query.return_value = ['NEWER_REPO']
|
||||
|
||||
with mock.patch('time.time') as _time:
|
||||
_time.return_value = now
|
||||
self.repo.expire_check()
|
||||
|
||||
self.session.getBuildTargets.assert_called_once()
|
||||
self.session.repo.query.assert_called_once()
|
||||
self.session.repoExpire.assert_called_once()
|
||||
|
||||
|
||||
# the end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue