本文整理汇总了Python中atomic_reactor.core.DockerTasker.retry_generator方法的典型用法代码示例。如果您正苦于以下问题:Python DockerTasker.retry_generator方法的具体用法?Python DockerTasker.retry_generator怎么用?Python DockerTasker.retry_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic_reactor.core.DockerTasker
的用法示例。
在下文中一共展示了DockerTasker.retry_generator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_retry_generator
# 需要导入模块: from atomic_reactor.core import DockerTasker [as 别名]
# 或者: from atomic_reactor.core.DockerTasker import retry_generator [as 别名]
def test_retry_generator(exc, in_init, retry_times):
def simplegen():
yield "log line"
my_args = ('some', 'new')
if not in_init:
my_kwargs = {'one': 'first', 'two': 'second', 'retry_times': retry_times}
else:
my_kwargs = {'one': 'first', 'two': 'second'}
if in_init:
t = DockerTasker(retry_times=retry_times)
else:
t = DockerTasker()
(flexmock(time)
.should_receive('sleep')
.and_return(None))
if not exc:
cr = CommandResult()
cr._error = "cmd_error"
cr._error_detail = {"message": "error_detail"}
if exc == APIError:
error_message = 'api_error'
response = flexmock(content=error_message, status_code=408)
(flexmock(atomic_reactor.util)
.should_receive('wait_for_command')
.times(retry_times + 1)
.and_raise(APIError, error_message, response))
elif exc == ProtocolError:
error_message = 'protocol_error'
(flexmock(atomic_reactor.util)
.should_receive('wait_for_command')
.times(retry_times + 1)
.and_raise(ProtocolError, error_message))
else:
(flexmock(atomic_reactor.util)
.should_receive('wait_for_command')
.times(retry_times + 1)
.and_return(cr))
error_message = 'cmd_error'
if retry_times >= 0:
with pytest.raises(RetryGeneratorException) as exc:
t.retry_generator(lambda *args, **kwargs: simplegen(),
*my_args, **my_kwargs)
assert repr(error_message) in repr(exc.value)
else:
t.retry_generator(lambda *args, **kwargs: simplegen(),
*my_args, **my_kwargs)