Skip to content

Commit

Permalink
FIX: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zofiaOS committed Oct 21, 2014
1 parent e5082b5 commit cd276fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -48,3 +48,6 @@ nosetests.xml

riemann.log
.libs

# vim
*.swp
44 changes: 28 additions & 16 deletions tests/workflow_tests/test_policies.py
Expand Up @@ -23,6 +23,13 @@
import time


NUM_OF_INITIAL_WORKFLOWS = 2
SAFETY_MARGIN = 2

# Autoheal constant
AUTOHEAL_EVENTS_MSG = "heart-beat"


class TestPolicies(TestCase):

def test_policies_flow(self):
Expand All @@ -35,7 +42,7 @@ def test_policies_flow(self):

self.publish(metric=metric_value)

self.wait_for_executions(3)
self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS + 1)
invocations = self.wait_for_invocations(deployment.id, 2)
self.assertEqual(self.instance_id, invocations[0]['node_id'])
self.assertEqual(123, invocations[1]['metric'])
Expand All @@ -48,7 +55,7 @@ def test_policies_flow_with_diamond(self):
self.deployment_id = deployment.id
self.instance_id = self.wait_for_node_instance().id
expected_metric_value = 42
self.wait_for_executions(3)
self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS + 1)
invocations = self.wait_for_invocations(deployment.id, 1)
self.assertEqual(expected_metric_value, invocations[0]['metric'])
finally:
Expand Down Expand Up @@ -123,40 +130,45 @@ def assertion(self, deployment_id, upper):
tester.publish_below_threshold(deployment.id, do_assert=False)

def test_autoheal_policy_triggering(self):
dsl_path = resource('dsl/simple_auto_heal_policy.yaml')
EVENTS_TTL = 3
AUTOHEAL_YAML = 'dsl/simple_auto_heal_policy.yaml'

dsl_path = resource(AUTOHEAL_YAML)
deployment, _ = deploy(dsl_path)
self.deployment_id = deployment.id
self.instance_id = self.wait_for_node_instance().id
self.wait_for_executions(2)

EVENTS_TTL = 3
self.publish("heart-beat", EVENTS_TTL)

# Two "buffer seconds"
time.sleep(EVENTS_TTL + Constants.PERIODICAL_EXPIRATION_INTERVAL + 2)
self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS)

self.wait_for_executions(3)
self.publish(AUTOHEAL_EVENTS_MSG, EVENTS_TTL)
time.sleep(
EVENTS_TTL +
Constants.PERIODICAL_EXPIRATION_INTERVAL +
SAFETY_MARGIN
)

self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS + 1)
invocations = self.wait_for_invocations(deployment.id, 1)

self.assertEqual("heart-beat-failure", invocations[0]['diagnose'])

def test_autoheal_policy_stability(self):
EVENTS_TTL = 3
EVENTS_NO = 10
AUTOHEAL_EVENTS_MSG = "heart-beat"
DEFAULT_WORKFLOW_NO = 2
AUTOHEAL_YAML = 'dsl/simple_auto_heal_policy.yaml'

dsl_path = resource('dsl/simple_auto_heal_policy.yaml')
dsl_path = resource(AUTOHEAL_YAML)
deployment, _ = deploy(dsl_path)
self.deployment_id = deployment.id
self.instance_id = self.wait_for_node_instance().id
self.wait_for_executions(DEFAULT_WORKFLOW_NO)

self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS)

for _ in range(EVENTS_NO):
self.publish(AUTOHEAL_EVENTS_MSG, EVENTS_TTL)
time.sleep(EVENTS_TTL - 2)
self.wait_for_executions(DEFAULT_WORKFLOW_NO)
time.sleep(EVENTS_TTL - SAFETY_MARGIN)

self.wait_for_executions(NUM_OF_INITIAL_WORKFLOWS)

def wait_for_executions(self, expected_count):
def assertion():
Expand Down

0 comments on commit cd276fa

Please sign in to comment.