mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Add tests for timeouts to client tests. In addition this makes all of the client functions have the same functionality
This commit is contained in:
parent
c8f15230f5
commit
6b91d539b8
@ -888,15 +888,19 @@ class LocalClient(object):
|
|||||||
if int(time.time()) > timeout_at:
|
if int(time.time()) > timeout_at:
|
||||||
# The timeout has been reached, check the jid to see if the
|
# The timeout has been reached, check the jid to see if the
|
||||||
# timeout needs to be increased
|
# timeout needs to be increased
|
||||||
|
if timeout > 0:
|
||||||
|
last_time = True
|
||||||
|
continue
|
||||||
|
else:
|
||||||
jinfo = self.gather_job_info(jid, tgt, tgt_type, minions - found, **kwargs)
|
jinfo = self.gather_job_info(jid, tgt, tgt_type, minions - found, **kwargs)
|
||||||
still_running = [id_ for id_, jdat in jinfo.iteritems()
|
more_time = [id_ for id_, jdat in jinfo.iteritems()
|
||||||
if jdat
|
if jdat
|
||||||
]
|
]
|
||||||
if still_running:
|
if more_time:
|
||||||
timeout_at = int(time.time()) + timeout
|
timeout_at = int(time.time()) + timeout
|
||||||
log.debug(
|
log.debug(
|
||||||
'jid {0} still running on {1} will now timeout at {2}'.format(
|
'jid {0} still running on {1} will now timeout at {2}'.format(
|
||||||
jid, still_running, datetime.fromtimestamp(timeout_at).time()
|
jid, more_time, datetime.fromtimestamp(timeout_at).time()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@ -1090,6 +1094,7 @@ class LocalClient(object):
|
|||||||
# All minions have returned, break out of the loop
|
# All minions have returned, break out of the loop
|
||||||
break
|
break
|
||||||
if int(time.time()) > timeout_at:
|
if int(time.time()) > timeout_at:
|
||||||
|
if timeout > 0:
|
||||||
if verbose or show_timeout:
|
if verbose or show_timeout:
|
||||||
if self.opts.get('minion_data_cache', False) \
|
if self.opts.get('minion_data_cache', False) \
|
||||||
or tgt_type in ('glob', 'pcre', 'list'):
|
or tgt_type in ('glob', 'pcre', 'list'):
|
||||||
@ -1101,6 +1106,25 @@ class LocalClient(object):
|
|||||||
'ret': 'Minion did not return'
|
'ret': 'Minion did not return'
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
jinfo = self.gather_job_info(jid,
|
||||||
|
tgt,
|
||||||
|
tgt_type,
|
||||||
|
minions - found,
|
||||||
|
)
|
||||||
|
more_time = False
|
||||||
|
for id_ in jinfo:
|
||||||
|
if jinfo[id_]:
|
||||||
|
if verbose:
|
||||||
|
print(
|
||||||
|
'Execution is still running on {0}'.format(id_)
|
||||||
|
)
|
||||||
|
more_time = True
|
||||||
|
if not more_time:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
timeout_at = time.time() + timeout
|
||||||
|
continue
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -1233,11 +1257,10 @@ class LocalClient(object):
|
|||||||
if 'retcode' in cache_jinfo[id_]:
|
if 'retcode' in cache_jinfo[id_]:
|
||||||
ret[id_]['retcode'] = cache_jinfo[id_]['retcode']
|
ret[id_]['retcode'] = cache_jinfo[id_]['retcode']
|
||||||
yield ret
|
yield ret
|
||||||
if more_time:
|
last_time = True
|
||||||
|
else:
|
||||||
timeout_at = time.time() + timeout
|
timeout_at = time.time() + timeout
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
last_time = True
|
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
def get_event_iter_returns(self, jid, minions, timeout=None):
|
def get_event_iter_returns(self, jid, minions, timeout=None):
|
||||||
|
@ -24,12 +24,7 @@ class StdTest(integration.ModuleCase):
|
|||||||
for ret in cmd_iter:
|
for ret in cmd_iter:
|
||||||
self.assertTrue(ret['minion'])
|
self.assertTrue(ret['minion'])
|
||||||
|
|
||||||
def test_cli_timeout(self):
|
# Test timeouts, a timeout of > 0 should timeout
|
||||||
'''
|
|
||||||
Test cli timeouts. A timeout > 0 should timeout, and a timeout of 0 means
|
|
||||||
wait until all returns complete
|
|
||||||
'''
|
|
||||||
# verify that timeouts work
|
|
||||||
cmd_iter = self.client.cmd_cli(
|
cmd_iter = self.client.cmd_cli(
|
||||||
'minion',
|
'minion',
|
||||||
'test.sleep',
|
'test.sleep',
|
||||||
@ -39,7 +34,7 @@ class StdTest(integration.ModuleCase):
|
|||||||
self.assertRaises(StopIteration,
|
self.assertRaises(StopIteration,
|
||||||
cmd_iter.next)
|
cmd_iter.next)
|
||||||
|
|
||||||
# verify that timeout of 0 waits
|
# A timeout of 0 means wait until done
|
||||||
cmd_iter = self.client.cmd_cli(
|
cmd_iter = self.client.cmd_cli(
|
||||||
'minion',
|
'minion',
|
||||||
'test.sleep',
|
'test.sleep',
|
||||||
@ -63,6 +58,29 @@ class StdTest(integration.ModuleCase):
|
|||||||
for ret in cmd_iter:
|
for ret in cmd_iter:
|
||||||
self.assertTrue(ret['minion'])
|
self.assertTrue(ret['minion'])
|
||||||
|
|
||||||
|
# Test timeouts, a timeout of > 0 should timeout
|
||||||
|
cmd_iter = self.client.cmd_iter(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=2
|
||||||
|
)
|
||||||
|
self.assertRaises(StopIteration,
|
||||||
|
cmd_iter.next)
|
||||||
|
|
||||||
|
# A timeout of 0 means wait until done
|
||||||
|
cmd_iter = self.client.cmd_iter(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=0
|
||||||
|
)
|
||||||
|
num_ret = 0
|
||||||
|
for ret in cmd_iter:
|
||||||
|
num_ret += 1
|
||||||
|
self.assertTrue(ret['minion'])
|
||||||
|
assert num_ret > 0
|
||||||
|
|
||||||
def test_iter_no_block(self):
|
def test_iter_no_block(self):
|
||||||
'''
|
'''
|
||||||
test cmd_iter_no_block
|
test cmd_iter_no_block
|
||||||
@ -76,6 +94,35 @@ class StdTest(integration.ModuleCase):
|
|||||||
continue
|
continue
|
||||||
self.assertTrue(ret['minion'])
|
self.assertTrue(ret['minion'])
|
||||||
|
|
||||||
|
# Test timeouts, a timeout of > 0 should timeout
|
||||||
|
cmd_iter = self.client.cmd_iter_no_block(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=2
|
||||||
|
)
|
||||||
|
num_ret = 0
|
||||||
|
for ret in cmd_iter:
|
||||||
|
if ret is None:
|
||||||
|
continue
|
||||||
|
num_ret += 1
|
||||||
|
assert num_ret == 0
|
||||||
|
|
||||||
|
# A timeout of 0 means wait until done
|
||||||
|
cmd_iter = self.client.cmd_iter_no_block(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=0
|
||||||
|
)
|
||||||
|
num_ret = 0
|
||||||
|
for ret in cmd_iter:
|
||||||
|
if ret is None:
|
||||||
|
continue
|
||||||
|
num_ret += 1
|
||||||
|
self.assertTrue(ret['minion'])
|
||||||
|
assert num_ret > 0
|
||||||
|
|
||||||
def test_full_returns(self):
|
def test_full_returns(self):
|
||||||
'''
|
'''
|
||||||
test cmd_iter
|
test cmd_iter
|
||||||
@ -108,6 +155,24 @@ class StdTest(integration.ModuleCase):
|
|||||||
ret['minion']
|
ret['minion']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test timeouts, a timeout of > 0 should timeout
|
||||||
|
ret = self.client.cmd_full_return(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=2
|
||||||
|
)
|
||||||
|
assert len(ret) == 0
|
||||||
|
|
||||||
|
# A timeout of 0 means wait until done
|
||||||
|
ret = self.client.cmd_full_return(
|
||||||
|
'minion',
|
||||||
|
'test.sleep',
|
||||||
|
arg=[5],
|
||||||
|
timeout=0
|
||||||
|
)
|
||||||
|
assert len(ret) > 0
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from integration import run_tests
|
from integration import run_tests
|
||||||
run_tests(StdTest)
|
run_tests(StdTest)
|
||||||
|
Loading…
Reference in New Issue
Block a user