Exemple #1
0
    def testSendIOError(self):
        with Mock(IOError):
            with Reporter() as reporter:
                for _ in range(random.number(2, 20)):
                    reporter.send(random_args())

                self.assertTrue(pid_exists(reporter.pid))
Exemple #2
0
    def testErrorCached(self):
        with Mock(IOError) as mock:
            for i in range(report_promethues.RETRIES):
                self.assertEqual(mock.count, i)
                self._push()
                self.assertEqual(mock.count, i + 1)

            for _ in range(random.number(2, 20)):
                self._push()
                self.assertEqual(mock.count, report_promethues.RETRIES)
Exemple #3
0
    def testSendError(self):
        for error in [IOError, ImportError, IndexError, KeyError, ValueError]:
            with Mock(error):
                reporter = Reporter()
                reporter.start(daemon=False)

                for _ in range(random.number(2, 20)):
                    reporter.send(random_args())

                self.assertTrue(pid_exists(reporter.pid))

                # `finish` should not fail even if the reporter failed
                try:
                    reporter.finish()
                except:
                    self.fail('`finish` was not expected to raise an error')
Exemple #4
0
    def testFinish(self):
        for error in [None, ImportError, IndexError, KeyError, ValueError]:
            with Mock(error):
                for _ in range(random.number(2, 5)):
                    report_promethues.send(*random_args())

                    pid = report_promethues.REPORTER.pid
                    self.assertTrue(pid_exists(pid))

                    # `finish` should not fail even if the worker failed
                    try:
                        report_promethues.finish()
                    except:
                        self.fail(
                            '`finish` was not expected to raise an error')

                    self.assertFalse(pid_exists(pid))
                    self.assertIsNone(report_promethues.REPORTER)
Exemple #5
0
def random_args():
    reporter_name = random.string(chars=string.ascii_letters + string.digits)
    reporter_value = random.number()
    report_type = random.choice([_ for _ in report_promethues.ReportType])

    return (reporter_name, reporter_value, report_type)
Exemple #6
0
 def testSanity(self):
     with Mock() as mock:
         for i in range(random.number(2, 20)):
             self.assertEqual(mock.count, i)
             self._push()
             self.assertEqual(mock.count, i + 1)
Exemple #7
0
 def testReportParameter(self):
     with Mock():
         with Reporter() as reporter:
             reporter.reportParameter(
                 random.string(chars=string.ascii_letters), random.number())