Esempio n. 1
0
    def test_post(self):
        event = threading.Event()
        api_service = MockAPIService()
        fact_builder = FactBuilder()

        api_service.texts = []
        api_service.tested_error = False

        def post_message(text):
            if len(api_service.texts) == 1 and not api_service.tested_error:
                api_service.tested_error = True
                raise Exception('testing')

            api_service.texts.append(text)

            if len(api_service.texts) > 4:
                event.set()
                post_sched.stop()

        api_service.post_message = post_message

        post_sched = PostScheduler(fact_builder, self.db, api_service,
            interval=0.2, deviation=0.01, retry_delay=0.1)

        event.wait(timeout=5)
        post_sched.stop()
        post_sched.join(timeout=1)

        self.assertEqual(len(api_service.texts), 5)
        self.assertEqual(len(self.db.get_facts()), 5)