Adjusting now times for scheduler tests.

This commit is contained in:
Gareth J. Greenaway 2017-12-06 21:44:47 -08:00
parent 98457bca2f
commit c418b14f49
No known key found for this signature in database
GPG Key ID: 10B62F8A7CAD7A41
3 changed files with 14 additions and 10 deletions

View File

@ -1050,7 +1050,7 @@ class Schedule(object):
'''
log.trace('==== evaluating schedule =====')
log.trace('==== evaluating schedule now {} ====='.format(now))
def _splay(splaytime):
'''

View File

@ -5,6 +5,9 @@ from __future__ import absolute_import
import copy
import logging
import os
import time
import dateutil.parser as dateutil_parser
# Import Salt Testing libs
from tests.support.case import ModuleCase
@ -48,12 +51,12 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
'schedule': {
'job1': {
'function': 'test.ping',
'when': '11/29/2017 4pm',
'when': '11/29/2017 4:00pm',
}
}
}
run_time1 = 1512000000 - 1
run_time2 = 1512000000
run_time2 = int(time.mktime(dateutil_parser.parse('11/29/2017 4:00pm').timetuple()))
run_time1 = run_time2 - 1
# Add the job to the scheduler
self.schedule.opts.update(job)
@ -66,5 +69,4 @@ class SchedulerEvalTest(ModuleCase, SaltReturnAssertsMixin):
# Evaluate 1 second at the run time
self.schedule.eval(now=run_time2)
ret = self.schedule.job_status('job1')
log.info('=== ret {0} ==='.format(ret))
self.assertEqual(ret['_last_run'], run_time2)

View File

@ -5,6 +5,9 @@ from __future__ import absolute_import
import copy
import logging
import os
import time
import dateutil.parser as dateutil_parser
# Import Salt Testing libs
from tests.support.case import ModuleCase
@ -56,7 +59,7 @@ class SchedulerSkipTest(ModuleCase, SaltReturnAssertsMixin):
# Add job to schedule
self.schedule.opts.update(job)
run_time = 1512000000
run_time = int(time.mktime(dateutil_parser.parse('11/29/2017 4:00pm').timetuple()))
self.schedule.skip_job('job1', {'time': run_time})
# Run 11/29/2017 at 4pm
@ -65,10 +68,9 @@ class SchedulerSkipTest(ModuleCase, SaltReturnAssertsMixin):
self.assertNotIn('_last_run', ret)
# Run 11/29/2017 at 5pm
run_time = 1512003600
run_time = int(time.mktime(dateutil_parser.parse('11/29/2017 5:00pm').timetuple()))
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job1')
log.info('=== ret {0} ==='.format(ret))
self.assertEqual(ret['_last_run'], run_time)
def test_skip_during_range(self):
@ -92,13 +94,13 @@ class SchedulerSkipTest(ModuleCase, SaltReturnAssertsMixin):
self.schedule.opts.update(job)
# eval at 2:30pm, will not run during range.
run_time = 148045860
run_time = int(time.mktime(dateutil_parser.parse('11/29/2017 2:30pm').timetuple()))
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job1')
self.assertNotIn('_last_run', ret)
# eval at 3:30pm, will run.
run_time = 1480462200
run_time = int(time.mktime(dateutil_parser.parse('11/29/2017 3:30pm').timetuple()))
self.schedule.eval(now=run_time)
ret = self.schedule.job_status('job1')
self.assertEqual(ret['_last_run'], run_time)