mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Adding a couple tests to ensure that duration is included in state run results even when states do not run.
This commit is contained in:
parent
912347abc3
commit
359265869f
2 changed files with 29 additions and 0 deletions
|
@ -2334,8 +2334,11 @@ class State(object):
|
|||
run_dict = self.pre
|
||||
else:
|
||||
run_dict = running
|
||||
start_time, duration = _calculate_fake_duration()
|
||||
run_dict[tag] = {'changes': {},
|
||||
'result': False,
|
||||
'duration': duration,
|
||||
'start_time': start_time,
|
||||
'comment': comment,
|
||||
'__run_num__': self.__run_num,
|
||||
'__sls__': low['__sls__']}
|
||||
|
|
|
@ -1016,6 +1016,20 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
expected_result = 'State was not run because none of the onchanges reqs changed'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
def test_onchanges_requisite_with_duration(self):
|
||||
'''
|
||||
Tests a simple state using the onchanges requisite
|
||||
the state will not run but results will include duration
|
||||
'''
|
||||
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onchanges_simple')
|
||||
|
||||
# Then, test the result of the state run when changes are not expected to happen
|
||||
# and ensure duration is included in the results
|
||||
test_data = state_run['cmd_|-test_non_changing_state_|-echo "Should not run"_|-run']
|
||||
self.assertIn('duration', test_data)
|
||||
|
||||
# onfail tests
|
||||
|
||||
def test_onfail_requisite(self):
|
||||
|
@ -1069,6 +1083,18 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
expected_result = 'State was not run because onfail req did not change'
|
||||
self.assertIn(expected_result, test_data)
|
||||
|
||||
def test_onfail_requisite_with_duration(self):
|
||||
'''
|
||||
Tests a simple state using the onfail requisite
|
||||
'''
|
||||
|
||||
# Only run the state once and keep the return data
|
||||
state_run = self.run_function('state.sls', mods='requisites.onfail_simple')
|
||||
|
||||
# Then, test the result of the state run when a failure is not expected to happen
|
||||
test_data = state_run['cmd_|-test_non_failing_state_|-echo "Should not run"_|-run']
|
||||
self.assertIn('duration', test_data)
|
||||
|
||||
# listen tests
|
||||
|
||||
def test_listen_requisite(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue