Refactor test_task_retry to not rely on start_task
Some tests rely on starting same workflow at various tasks. This wont' work once start task is defined at workflow level. Fixing test_task_retry tests. Partially implements: blueprint mistral-workflow-start-task Change-Id: I3e7a2a09d7a17cf7924e678dad78a0c12bd7b03a
This commit is contained in:
parent
26dd56d7c9
commit
d325383863
20
mistral/tests/resources/retry_task/delay_retry_task.yaml
Normal file
20
mistral/tests/resources/retry_task/delay_retry_task.yaml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Namespaces:
|
||||||
|
MyService:
|
||||||
|
actions:
|
||||||
|
some-action:
|
||||||
|
class: std.mistral_http
|
||||||
|
base-parameters:
|
||||||
|
url: http://path_to_service/action_url
|
||||||
|
method: GET
|
||||||
|
output:
|
||||||
|
output: $
|
||||||
|
|
||||||
|
Workflow:
|
||||||
|
tasks:
|
||||||
|
delay_retry_task:
|
||||||
|
action: MyService.some-action
|
||||||
|
retry:
|
||||||
|
count: 2
|
||||||
|
delay: 0.1
|
||||||
|
publish:
|
||||||
|
rt_output: output
|
@ -8,12 +8,6 @@ Namespaces:
|
|||||||
method: GET
|
method: GET
|
||||||
output:
|
output:
|
||||||
output: $
|
output: $
|
||||||
sync-action:
|
|
||||||
class: std.echo
|
|
||||||
base-parameters:
|
|
||||||
output: Cheers!
|
|
||||||
output:
|
|
||||||
greeting: $
|
|
||||||
|
|
||||||
Workflow:
|
Workflow:
|
||||||
tasks:
|
tasks:
|
||||||
@ -23,24 +17,3 @@ Workflow:
|
|||||||
count: 5
|
count: 5
|
||||||
publish:
|
publish:
|
||||||
rt_output: $.output
|
rt_output: $.output
|
||||||
|
|
||||||
delay_retry_task:
|
|
||||||
action: MyService.some-action
|
|
||||||
retry:
|
|
||||||
count: 2
|
|
||||||
delay: 0.1
|
|
||||||
publish:
|
|
||||||
rt_output: output
|
|
||||||
|
|
||||||
no_retry_task:
|
|
||||||
action: MyService.some-action
|
|
||||||
publish:
|
|
||||||
n_rt_output: $.output
|
|
||||||
on-success: delay_retry_task
|
|
||||||
|
|
||||||
sync_task:
|
|
||||||
action: MyService.sync-action
|
|
||||||
retry:
|
|
||||||
count: 5
|
|
||||||
publish:
|
|
||||||
st_output: $.greeting
|
|
18
mistral/tests/resources/retry_task/sync_task.yaml
Normal file
18
mistral/tests/resources/retry_task/sync_task.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Namespaces:
|
||||||
|
MyService:
|
||||||
|
actions:
|
||||||
|
sync-action:
|
||||||
|
class: std.echo
|
||||||
|
base-parameters:
|
||||||
|
output: Cheers!
|
||||||
|
output:
|
||||||
|
greeting: $
|
||||||
|
|
||||||
|
Workflow:
|
||||||
|
tasks:
|
||||||
|
sync-task:
|
||||||
|
action: MyService.sync-action
|
||||||
|
retry:
|
||||||
|
count: 5
|
||||||
|
publish:
|
||||||
|
st_output: $.greeting
|
26
mistral/tests/resources/retry_task/two_tasks.yaml
Normal file
26
mistral/tests/resources/retry_task/two_tasks.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Namespaces:
|
||||||
|
MyService:
|
||||||
|
actions:
|
||||||
|
some-action:
|
||||||
|
class: std.mistral_http
|
||||||
|
base-parameters:
|
||||||
|
url: http://path_to_service/action_url
|
||||||
|
method: GET
|
||||||
|
output:
|
||||||
|
output: $
|
||||||
|
|
||||||
|
Workflow:
|
||||||
|
tasks:
|
||||||
|
no_retry_task:
|
||||||
|
action: MyService.some-action
|
||||||
|
publish:
|
||||||
|
n_rt_output: $.output
|
||||||
|
on-success: delay_retry_task
|
||||||
|
|
||||||
|
delay_retry_task:
|
||||||
|
action: MyService.some-action
|
||||||
|
retry:
|
||||||
|
count: 2
|
||||||
|
delay: 0.1
|
||||||
|
publish:
|
||||||
|
rt_output: output
|
@ -67,16 +67,15 @@ class FailBeforeSuccessMocker(object):
|
|||||||
@mock.patch.object(
|
@mock.patch.object(
|
||||||
concrete_engine.DefaultEngine, '_run_tasks',
|
concrete_engine.DefaultEngine, '_run_tasks',
|
||||||
mock.MagicMock(side_effect=base.EngineTestCase.mock_run_tasks))
|
mock.MagicMock(side_effect=base.EngineTestCase.mock_run_tasks))
|
||||||
@mock.patch.object(
|
|
||||||
db_api, 'workbook_get',
|
|
||||||
mock.MagicMock(
|
|
||||||
return_value={
|
|
||||||
'definition': base.get_resource('retry_task/retry_task.yaml')}))
|
|
||||||
@mock.patch.object(
|
@mock.patch.object(
|
||||||
std_actions.HTTPAction, 'run',
|
std_actions.HTTPAction, 'run',
|
||||||
mock.MagicMock(return_value='result'))
|
mock.MagicMock(return_value='result'))
|
||||||
class TaskRetryTest(base.EngineTestCase):
|
class TaskRetryTest(base.EngineTestCase):
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/retry_task.yaml')}))
|
||||||
def test_no_retry(self):
|
def test_no_retry(self):
|
||||||
execution = self.engine.start_workflow_execution(WB_NAME,
|
execution = self.engine.start_workflow_execution(WB_NAME,
|
||||||
'retry_task', None)
|
'retry_task', None)
|
||||||
@ -90,6 +89,10 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
self._assert_single_item(tasks, name='retry_task')
|
self._assert_single_item(tasks, name='retry_task')
|
||||||
self._assert_single_item(tasks, task_runtime_context=None)
|
self._assert_single_item(tasks, task_runtime_context=None)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/retry_task.yaml')}))
|
||||||
def test_retry_always_error(self):
|
def test_retry_always_error(self):
|
||||||
workbook = _get_workbook(WB_NAME)
|
workbook = _get_workbook(WB_NAME)
|
||||||
|
|
||||||
@ -112,6 +115,10 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
'retry_no': retry_count - 1})
|
'retry_no': retry_count - 1})
|
||||||
self._assert_single_item(tasks, state=states.ERROR)
|
self._assert_single_item(tasks, state=states.ERROR)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/retry_task.yaml')}))
|
||||||
def test_retry_eventual_success(self):
|
def test_retry_eventual_success(self):
|
||||||
workbook = _get_workbook(WB_NAME)
|
workbook = _get_workbook(WB_NAME)
|
||||||
|
|
||||||
@ -137,6 +144,10 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
self._assert_single_item(tasks, task_runtime_context={
|
self._assert_single_item(tasks, task_runtime_context={
|
||||||
'retry_no': retry_count / 2 - 1})
|
'retry_no': retry_count / 2 - 1})
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={'definition': base.get_resource(
|
||||||
|
'retry_task/delay_retry_task.yaml')}))
|
||||||
def test_retry_delay(self):
|
def test_retry_delay(self):
|
||||||
task_name = 'delay_retry_task'
|
task_name = 'delay_retry_task'
|
||||||
workbook = _get_workbook(WB_NAME)
|
workbook = _get_workbook(WB_NAME)
|
||||||
@ -174,6 +185,10 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
'retry_no': retry_count - 1})
|
'retry_no': retry_count - 1})
|
||||||
self._assert_single_item(tasks, state=states.ERROR)
|
self._assert_single_item(tasks, state=states.ERROR)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/two_tasks.yaml')}))
|
||||||
def test_from_no_retry_to_retry_task(self):
|
def test_from_no_retry_to_retry_task(self):
|
||||||
task_name_1 = 'no_retry_task'
|
task_name_1 = 'no_retry_task'
|
||||||
task_name_2 = 'delay_retry_task'
|
task_name_2 = 'delay_retry_task'
|
||||||
@ -225,27 +240,35 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
|
|
||||||
@mock.patch.object(std_actions.EchoAction, "run",
|
@mock.patch.object(std_actions.EchoAction, "run",
|
||||||
mock.MagicMock(side_effect=exc.ActionException))
|
mock.MagicMock(side_effect=exc.ActionException))
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/sync_task.yaml')}))
|
||||||
def test_sync_action_always_error(self):
|
def test_sync_action_always_error(self):
|
||||||
task_name_1 = 'sync_task'
|
|
||||||
workbook = _get_workbook(WB_NAME)
|
workbook = _get_workbook(WB_NAME)
|
||||||
task_spec = workbook.tasks.get(task_name_1)
|
start_task = 'sync-task'
|
||||||
|
task_spec = workbook.tasks.get(start_task)
|
||||||
retry_count, _, __ = task_spec.get_retry_parameters()
|
retry_count, _, __ = task_spec.get_retry_parameters()
|
||||||
|
|
||||||
execution = self.engine.start_workflow_execution(WB_NAME,
|
execution = self.engine.start_workflow_execution(WB_NAME,
|
||||||
task_name_1, None)
|
start_task, None)
|
||||||
|
|
||||||
# TODO(rakhmerov): It's not stable, need to avoid race condition.
|
# TODO(rakhmerov): It's not stable, need to avoid race condition.
|
||||||
tasks = db_api.tasks_get(WB_NAME, execution['id'])
|
tasks = db_api.tasks_get(WB_NAME, execution['id'])
|
||||||
|
|
||||||
self._assert_single_item(tasks, name=task_name_1)
|
self._assert_single_item(tasks, name=start_task)
|
||||||
self._assert_single_item(tasks, task_runtime_context={
|
self._assert_single_item(tasks, task_runtime_context={
|
||||||
'retry_no': retry_count - 1})
|
'retry_no': retry_count - 1})
|
||||||
self._assert_single_item(tasks, state=states.ERROR)
|
self._assert_single_item(tasks, state=states.ERROR)
|
||||||
|
|
||||||
|
@mock.patch.object(
|
||||||
|
db_api, 'workbook_get',
|
||||||
|
mock.MagicMock(return_value={
|
||||||
|
'definition': base.get_resource('retry_task/sync_task.yaml')}))
|
||||||
def test_sync_action_eventual_success(self):
|
def test_sync_action_eventual_success(self):
|
||||||
task_name_1 = 'sync_task'
|
start_task = 'sync-task'
|
||||||
workbook = _get_workbook(WB_NAME)
|
workbook = _get_workbook(WB_NAME)
|
||||||
task_spec = workbook.tasks.get(task_name_1)
|
task_spec = workbook.tasks.get(start_task)
|
||||||
retry_count, _, __ = task_spec.get_retry_parameters()
|
retry_count, _, __ = task_spec.get_retry_parameters()
|
||||||
|
|
||||||
# After a pre-set no of retries the mock method will return a
|
# After a pre-set no of retries the mock method will return a
|
||||||
@ -255,12 +278,13 @@ class TaskRetryTest(base.EngineTestCase):
|
|||||||
with mock.patch.object(std_actions.EchoAction, "run",
|
with mock.patch.object(std_actions.EchoAction, "run",
|
||||||
side_effect=mock_functor.mock_partial_failure):
|
side_effect=mock_functor.mock_partial_failure):
|
||||||
execution = self.engine.start_workflow_execution(WB_NAME,
|
execution = self.engine.start_workflow_execution(WB_NAME,
|
||||||
task_name_1, None)
|
start_task,
|
||||||
|
None)
|
||||||
|
|
||||||
# TODO(rakhmerov): It's not stable, need to avoid race condition.
|
# TODO(rakhmerov): It's not stable, need to avoid race condition.
|
||||||
tasks = db_api.tasks_get(WB_NAME, execution['id'])
|
tasks = db_api.tasks_get(WB_NAME, execution['id'])
|
||||||
|
|
||||||
self._assert_single_item(tasks, name=task_name_1)
|
self._assert_single_item(tasks, name=start_task)
|
||||||
self._assert_single_item(tasks, task_runtime_context={
|
self._assert_single_item(tasks, task_runtime_context={
|
||||||
'retry_no': retry_count / 2})
|
'retry_no': retry_count / 2})
|
||||||
self._assert_single_item(tasks, state=states.SUCCESS)
|
self._assert_single_item(tasks, state=states.SUCCESS)
|
||||||
|
Loading…
Reference in New Issue
Block a user