From 716776a58ed02cf6ec2e0dd0903ff6f48fbdec10 Mon Sep 17 00:00:00 2001 From: Dawid Deja Date: Wed, 22 Jun 2016 11:26:30 +0200 Subject: [PATCH] Remove std.mistral_http action from tests Unit tests should not rely on internet connection. This commit adds new 'std.sleep' action that can symulate long running action. Change-Id: Ib7bede239942d429d1bb1ed6f5a2611f64520848 Closes-bug: 1538996 --- mistral/actions/std_actions.py | 27 +++++++++++++++++++ .../tests/unit/engine/test_workflow_resume.py | 2 +- setup.cfg | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mistral/actions/std_actions.py b/mistral/actions/std_actions.py index 2379b516..b9b9b2b8 100644 --- a/mistral/actions/std_actions.py +++ b/mistral/actions/std_actions.py @@ -21,6 +21,7 @@ from email.mime import text import json import requests import smtplib +import time from mistral.actions import base from mistral import exceptions as exc @@ -432,3 +433,29 @@ class JavaScriptAction(base.Action): def test(self): return self.script + + +class SleepAction(base.Action): + """Sleep action. + + This action sleeps for given amount of seconds. It can be mostly useful + for testing and debugging purposes. + """ + def __init__(self, seconds=1): + try: + self._seconds = int(seconds) + self._seconds = 0 if self._seconds < 0 else self._seconds + except ValueError: + self._seconds = 0 + + def run(self): + LOG.info('Running sleep action [seconds=%s]' % self._seconds) + + time.sleep(self._seconds) + + return None + + def test(self): + time.sleep(1) + + return None diff --git a/mistral/tests/unit/engine/test_workflow_resume.py b/mistral/tests/unit/engine/test_workflow_resume.py index 4384fdfd..f87abd8a 100644 --- a/mistral/tests/unit/engine/test_workflow_resume.py +++ b/mistral/tests/unit/engine/test_workflow_resume.py @@ -171,7 +171,7 @@ workflows: - pause task2: - action: std.mistral_http url="http://google.com" + action: std.async_noop # This one won't be finished when execution is already PAUSED. on-complete: - task4 diff --git a/setup.cfg b/setup.cfg index e876fade..bbd7b409 100644 --- a/setup.cfg +++ b/setup.cfg @@ -60,3 +60,4 @@ mistral.actions = std.ssh_proxied = mistral.actions.std_actions:SSHProxiedAction std.email = mistral.actions.std_actions:SendEmailAction std.javascript = mistral.actions.std_actions:JavaScriptAction + std.sleep = mistral.actions.std_actions:SleepAction