Beispiel #1
0
    def test_When_complex_concurrent_scenario_The_shit_works_2(self):
        ruleset = RuleSet([(rule1, {
            'id': 'rule1',
            'maxCount': 1
        }), (rule3, {
            'id': 'rule3',
            'maxCount': 2
        })], self.context)

        # matches evt #1 in rule3 instance 1
        # ie. event-3.1-seen = 1
        ruleset.onEvent(Event(service='tellstick', key='switch-1'))
        time.sleep(0.1)

        # matches evt #1 in rule1 instance 1
        # and next evt (#2) in rule3 instance 1 - but it is busy so nothing happens
        # ie. event-1.1-seen = 1
        ruleset.onEvent(Event(service='tellstick', key='switch-2'))
        time.sleep(0.3)

        # matches evt #1 in rule3 instance 2
        # ie. event-3.1-seen = 2
        ruleset.onEvent(Event(service='tellstick', key='switch-1'))
        time.sleep(0.1)

        # matches evt #1 in rule1, which is done, so new is spawned
        # and matches next evt (#2) in rule3 instance 1 that is now done running actions
        # and matches next evt (#2) in rule3 instance 2 but it is busy
        # ie. event-1.1-seen = 2 and event-3.2-seen = 2
        ruleset.onEvent(Event(service='tellstick', key='switch-2'))
        time.sleep(0.3)

        self.assertEqual(self.context.test['event-1.1-seen'], 2)
        self.assertEqual(self.context.test['event-3.1-seen'], 2)
        self.assertEqual(self.context.test['event-3.2-seen'], 1)
Beispiel #2
0
    def test_When_complex_concurrent_scenario_The_shit_works_2(self):
        ruleset = RuleSet(
            [(rule1, {"id": "rule1", "maxCount": 1}), (rule3, {"id": "rule3", "maxCount": 2})], self.context
        )

        # matches evt #1 in rule3 instance 1
        # ie. event-3.1-seen = 1
        ruleset.onEvent(Event(service="tellstick", key="switch-1"))
        time.sleep(0.1)

        # matches evt #1 in rule1 instance 1
        # and next evt (#2) in rule3 instance 1 - but it is busy so nothing happens
        # ie. event-1.1-seen = 1
        ruleset.onEvent(Event(service="tellstick", key="switch-2"))
        time.sleep(0.3)

        # matches evt #1 in rule3 instance 2
        # ie. event-3.1-seen = 2
        ruleset.onEvent(Event(service="tellstick", key="switch-1"))
        time.sleep(0.1)

        # matches evt #1 in rule1, which is done, so new is spawned
        # and matches next evt (#2) in rule3 instance 1 that is now done running actions
        # and matches next evt (#2) in rule3 instance 2 but it is busy
        # ie. event-1.1-seen = 2 and event-3.2-seen = 2
        ruleset.onEvent(Event(service="tellstick", key="switch-2"))
        time.sleep(0.3)

        self.assertEqual(self.context.test["event-1.1-seen"], 2)
        self.assertEqual(self.context.test["event-3.1-seen"], 2)
        self.assertEqual(self.context.test["event-3.2-seen"], 1)
Beispiel #3
0
    def test_When_complex_concurrent_scenario_The_shit_works(self):
        ruleset = RuleSet([(rule1, {
            'id': 'rule1',
            'maxCount': 1
        }), (rule2, {
            'id': 'rule2',
            'maxCount': 1
        }), (rule3, {
            'id': 'rule3',
            'maxCount': 1
        })], self.context)

        ruleset.onEvent(Event(service='tellstick', key='switch-1'))
        time.sleep(0.1)

        ruleset.onEvent(Event(service='tellstick', key='switch-2'))
        time.sleep(0.3)

        ruleset.onEvent(Event(service='tellstick', key='switch-3'))
        time.sleep(0.3)

        self.assertTrue(self.context.test.has_key('event-1.1-seen'))
        self.assertTrue(self.context.test.has_key('event-2.1-seen'))
        self.assertTrue(self.context.test.has_key('event-2.2-seen'))
        self.assertTrue(self.context.test.has_key('event-2.3-seen'))
        self.assertTrue(self.context.test.has_key('event-3.1-seen'))
Beispiel #4
0
    def test_When_complex_concurrent_scenario_The_shit_works(self):
        ruleset = RuleSet(
            [
                (rule1, {"id": "rule1", "maxCount": 1}),
                (rule2, {"id": "rule2", "maxCount": 1}),
                (rule3, {"id": "rule3", "maxCount": 1}),
            ],
            self.context,
        )

        ruleset.onEvent(Event(service="tellstick", key="switch-1"))
        time.sleep(0.1)

        ruleset.onEvent(Event(service="tellstick", key="switch-2"))
        time.sleep(0.3)

        ruleset.onEvent(Event(service="tellstick", key="switch-3"))
        time.sleep(0.3)

        self.assertTrue(self.context.test.has_key("event-1.1-seen"))
        self.assertTrue(self.context.test.has_key("event-2.1-seen"))
        self.assertTrue(self.context.test.has_key("event-2.2-seen"))
        self.assertTrue(self.context.test.has_key("event-2.3-seen"))
        self.assertTrue(self.context.test.has_key("event-3.1-seen"))